Other Parts Discussed in Thread: CC2531
Hi team,
Do we have any example code for using UART to print to the console (for debugging purposes) for the CC2531?
Regards,
Akash Patel
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Other Parts Discussed in Thread: CC2531
Hi team,
Do we have any example code for using UART to print to the console (for debugging purposes) for the CC2531?
Regards,
Akash Patel
Hi Akash,
Here's some very simple code to use UART as printf();
void uart0Setup(void);
void uartPutc(uint8 c);
int main()
{
uartPutc('H');
uartPutc('e');
uartPutc('l');
uartPutc('l');
uartPutc('o');
uartPutc(' ');
uartPutc('W');
uartPutc('o');
uartPutc('r');
uartPutc('l');
uartPutc('d');
}
void uart0Setup(void)
{
#if 1
PERCFG |= 0x02; // Alternative 2 for USART 1
P2DIR &= ~(0xC0); //
P2DIR |= (0x40); // USART1 peripheral priority 1
P1SEL |= 0xC0; // Set P1_6 and P1_7 as peripheral pins
U1UCR |= 0x80; // Reset USART1
U1CSR = 0x80; // Set USART1 -> UART mode
U1GCR = 12; // Generic settings, BAUD_E for 230400
U1BAUD = 216; // BAUD_M for 115000
#else
PERCFG &= ~(0x01); // Alternative 1 for USART 0
P2DIR &= ~(0xC0); // USART0 peripheral priority 1
P0SEL |= 0x0C; // Set P0_2 and P0_3 as peripheral pins
U0UCR |= 0x80; // Reset USART0
U0CSR = 0x80; // Set USART0 -> UART mode
// U0GCR = 0x08; // Generic settings, BAUD_E for 9600
// U0BAUD = 59; // BAUD_M for 9600
// U0GCR = 11; // Generic settings, BAUD_E for 115000
U0GCR = 12; // Generic settings, BAUD_E for 230400
U0BAUD = 216; // BAUD_M for 115000
#endif
}
void uartPutc(uint8 c)
{
#if 1
while((U1CSR & 0x01)); // Wait until ACTIVE bit is low
U1DBUF = c;
#else
while((U0CSR & 0x01)); // Wait until ACTIVE bit is low
U0DBUF = c;
#endif
}