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);
}
thanks