SAM4SD32C change USART baud rate problem

Discussion around product based on ARM Cortex M4 core.
This forum will be discontinued soon.

Moderators: nferre, ncollot

christianyudhistira
Posts: 3
Joined: Tue Nov 22, 2016 9:25 am

SAM4SD32C change USART baud rate problem

Mon Dec 26, 2016 12:15 pm

Hello,

I am using SAM4SD32C to develop a cryptoauthentication application that using ECC508A device with SWI interface.
I generate SWI communication by using UART method. My goal is to achieve the baud rate with value of 230400 baud for running the crypto function, but in the first sequence I need to use 115200 baud rate to send the wake up signal to the device.
I have successfully implemented wake up code that using 115200 baud rate, but after I create additional code
to change the baud rate value, my application doesn't work entirely (the previous wake up code also doesn't work).

I have been looking for answer to my issue but still not getting any results. Here is my code implementation to wake up the device and change the baud rate value.

Code: Select all


#define UART_SERIAL_BAUDRATE     115200
#define UART_SERIAL_MODE         UART_MR_PAR_NO

#define PINS_UART1          (PIO_PB2A_URXD1 | PIO_PB3A_UTXD1)
#define PINS_UART1_FLAGS    (PIO_PERIPH_A | PIO_DEFAULT)
#define PINS_UART1_MASK     (PIO_PB2A_URXD1| PIO_PB3A_UTXD1 )
#define PINS_UART1_PIO      PIOB		  //Rx and Tx pins are in Parallel IO B
#define PINS_UART1_ID       ID_PIOB
#define PINS_UART1_TYPE     PIO_PERIPH_A  //UART1 is part of Peripheral A pg. 762 SAM4S Data sheet
#define PINS_UART1_ATTR     PIO_DEFAULT

int main (void)
{
	sysclk_init();
	board_init();
	
	pio_configure(PINS_UART1_PIO, PINS_UART1_TYPE, PINS_UART1_MASK, PINS_UART1_ATTR);
	pmc_enable_periph_clk(ID_UART1);
	
	sam_uart_opt_t uart1_sett =
	{ sysclk_get_cpu_hz(), UART_SERIAL_BAUDRATE, UART_SERIAL_MODE };
	
        // init UART
	uart_init(UART1,&uart1_sett);
	
	uart_enable_interrupt(UART1,UART_IER_RXRDY);
	NVIC_EnableIRQ(UART1_IRQn);
	
	// send wake up signal
	while (!(UART1->UART_SR & UART_SR_TXRDY));
	uart_write(UART1, (uint8_t)0x00);
	
	// change baud rate
	uart_disable(UART1);
	uart1_sett.ul_baudrate = 230400;
	uart_init(UART1,&uart1_sett);
	uart_enable(UART1);

}
Does anyone have any suggestion about this issue?

thanks
tsvoipio
Posts: 54
Joined: Wed Aug 19, 2015 9:44 pm

Re: SAM4SD32C change USART baud rate problem

Tue Dec 27, 2016 4:10 pm

You're speaking of both UART and USART. A SAM4SD32 has both, and they are distinct units. Luckily, the relevant register bits happen to be the same in both units.

Maybe you're killing the wake-up byte before it is sent. The write to the transmitter holding register starts the transmission, but if the uart_disable() function either drops the TXEN bit in the command register or activates the RSTTX bit in the same register, you'll lose the wake-up byte before it is even started to send.

You could wait for the TXEMPTY bit in the status register before resetting the unit.
lesher
Posts: 1
Joined: Thu Dec 08, 2016 6:42 pm

Re: SAM4SD32C change USART baud rate problem

Wed Dec 28, 2016 11:37 pm

See the ASF example called "Low Power Application".
There's a function called "reconfigure_console().

My first recommendation is to see if the Tx pin is wiggling at the expected rate.

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest