/*
PTE16,PTE17
*/
void u2_init(void)
{
/*
10.3.1 K70 Signal Multiplexing and Pin Assignments(page 275)
*/
int floor_val;
#if TOWER_K70_BOARD
PORTE->PCR[16] = PORT_PCR_MUX(3);
PORTE->PCR[17] = PORT_PCR_MUX(3);
#elif K70_MASTER_V2
PORTD->PCR[2] = PORT_PCR_MUX(3);
PORTD->PCR[3] = PORT_PCR_MUX(3);
#endif
/*
UART baud rate = UART module clock / (16 × (SBR[12:0] + BRFD))
sbr = 60.0e6/(115200*16)=32.552083333333336
BRFA = (0.552083333333336 * 32)= 17.666666666666742
*/
floor_val = BusClock/(115200*16);
UART2->C4 = 18; //?????
UART2->BDH = (floor_val>>8) & 0x1F; //????115200bps
UART2->BDL = floor_val&0xFF;
// UART2->C2 |= UART_C2_TE_MASK|UART_C2_RE_MASK; //????,??
#if U2_TX_DMA
UART2->C2 |= UART_C2_TE_MASK|UART_C2_TIE_MASK|UART_C2_RE_MASK | UART_C2_RIE_MASK; //????,??
UART2->C2 &= ~UART_C2_TCIE_MASK;
#else
UART2->C2 = UART_C2_TE_MASK |UART_C2_RE_MASK | UART_C2_RIE_MASK;
#endif
// UART2->PFIFO = UART_PFIFO_TXFIFOSIZE(0x6)|UART_PFIFO_TXFE_MASK;
// UART2->PFIFO = (0x6ul <<4)|UART_PFIFO_TXFE_MASK;
// UART2->CFIFO = UART_CFIFO_TXFLUSH_MASK | UART_CFIFO_RXFLUSH_MASK;
#if U2_TX_DMA
UART2->C5 = UART_C5_TDMAS_MASK;
#endif
NVIC_EnableIRQ(UART2_RX_TX_IRQn);
u2_tx_insert_idx = 0;
u2_tx_extract_idx = 0;
}
如果楼主用MDK,抄这段代码就差不多了. |