Hello,
For a project I'm currently working with the SAMD21J18A and I'm for this it is necessary to send DATA over USART.
This for both debugging and application purposes.
I configured the UART according to the SAMD21 datasheet.
The pin on which I have a data analyzer connected are PB30 for TX and PB31 for RX which have the SERCOM 5 on D.
The issue is that I'm not getting the message on the data analyzer that I'm trying to send over UART communication.
Pin Initialization
HAL_GPIO_PIN(UART_TX, B, 30)
HAL_GPIO_PIN(UART_RX, B, 31)
USART Initialization
static void uart_init2(uint32_t baud)
{
uint64_t baudrate = (uint64_t)65536 * (8000000 - 16 * baud) / 8000000;
HAL_GPIO_UART_TX_out();
HAL_GPIO_UART_TX_pmuxen(PORT_PMUX_PMUXE_D_Val);
HAL_GPIO_UART_RX_in();
HAL_GPIO_UART_RX_pmuxen(PORT_PMUX_PMUXE_D_Val);
PM->APBCMASK.reg |= PM_APBCMASK_SERCOM5;
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(SERCOM5_GCLK_ID_CORE) |
GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN(0);
SERCOM5->USART.CTRLA.reg =
SERCOM_USART_CTRLA_DORD | SERCOM_USART_CTRLA_MODE_USART_INT_CLK |
SERCOM_USART_CTRLA_RXPO(0x1) | SERCOM_USART_CTRLA_TXPO(0x0);
SERCOM5->USART.CTRLB.reg = SERCOM_USART_CTRLB_RXEN | SERCOM_USART_CTRLB_TXEN |
SERCOM_USART_CTRLB_CHSIZE(0);
SERCOM5->USART.BAUD.reg = (uint16_t)baudrate+1;
SERCOM5->USART.CTRLA.reg |= SERCOM_USART_CTRLA_ENABLE;
}
Writing and main:
static void uart_putc(char c)
{
while (!(SERCOM5->USART.INTFLAG.reg & SERCOM_USART_INTFLAG_DRE));
SERCOM5->USART.DATA.reg = c;
}
static void uart_puts(char *s)
{
while (*s)
uart_putc(*s++);
}
int main(void)
{
SystemInit();
GPIO_Init();
TMR_Init();
uart_init2(115200);
uart_puts("Hello, world!");
while (1)
{
}
}
The attachment show the output of the code that is used.
The usart start whos the output from the start of the code and the rest are screenshots of the remaining output.
The baudrate im trying to communicate on is 115200.