yefj
Advanced Member level 4
Hello I have build bellow the basic stuff of UART initialization .
Now i need to do the operations with sending and receiving DATA registers.
regarding sending the data:
I need to make sure the TXS flag in USARTn_STATUS register is SET,also we use TXDATA register which table shown bellow.
So using CMSIS style writing,but i am not sure regaring two things:
1.how exactly should i define the inverted bitmask that uses to clear the old TXDATA
2.how do i define the binary 5 and in the send register.
Now i need to do the operations with sending and receiving DATA registers.
regarding sending the data:
I need to make sure the TXS flag in USARTn_STATUS register is SET,also we use TXDATA register which table shown bellow.
So using CMSIS style writing,but i am not sure regaring two things:
1.how exactly should i define the inverted bitmask that uses to clear the old TXDATA
2.how do i define the binary 5 and in the send register.
Code:
if (USART_STATUS_TXC==0) /* Transmition has not started yet */
{
USART0->TXDATA=(USAT0->TXDATA&~_USART_STATUS_TXDATA_MASK)|0b0101) /*send binary 5 from Tx */
USART0->STATUS=(USAT0->STATUS&~_USART_STATUS_TXC_MASK)|USART_STATUS_TXC) /*Transmition finished*/
}
Code:
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
#include "em_chip.h"
#define BUFFER_SIZE 80
char buffer[BUFFER_SIZE];
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
char welcome_string[] = "Silicon Labs UART Code example!\r\f";
int i,j;
// Chip errata
CHIP_Init();
// Enable oscillator to GPIO and USART1 modules
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_USART0, true);
// set pin modes for UART TX and RX pins
GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
// Initialize USART asynchronous mode and route pins
USART_InitAsync(USART0, &init);
USART0->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN;
if (USART_STATUS_TXC==0) /* Transmition has not started yet */
{
USART0->TXDATA=(USAT0->TXDATA&~_USART_STATUS_TXDATA_MASK)|0b0101) /*send binary 5 from Tx */
USART0->STATUS=(USAT0->STATUS&~_USART_STATUS_TXC_MASK)|USART_STATUS_TXC) /*Transmition finished*/
}