- Add the following macros and
variables outside the main()
function:
#define RX_BUFFER_SIZE 1
#define TX_BUFFER_SIZE 1
volatile bool USART1_writeStatus = false;
volatile bool USART1_readStatus = false;
volatile bool USART0_writeStatus = false;
volatile bool USART0_readStatus = false;
uint8_t rxBuffer;
uint8_t txBuffer = 0xAA;
Figure 5-57. Adding the Macros and
Variables
- Add the
RTS_ENABLE
and RTS_DISABLE
functions outside the main() function to manually
control the RTS lines:void RTS_ENABLE(void)
{
USART0_REGS->US_CR = US_CR_USART_RTSEN_Msk;
}
void RTS_DISABLE(void)
{
USART0_REGS->US_CR = US_CR_USART_RTSDIS_Msk;
}
Figure 5-58. Adding the RTS
Functions
- Add event handlers and enable the
hardware handshaking mode outside the main()
function:
void USART0_WriteEventHandler ( uintptr_t context )
{
USART0_writeStatus = true;
}
void USART0_ReadEventHandler (uintptr_t context)
{
RTS_ENABLE();
USART0_readStatus = true;
}
void ext_usart_init()
{
USART0_REGS->US_MR |= US_MR_USART_MODE_HW_HANDSHAKING;
}
Figure 5-59. Adding Event
Handlers
- Call the necessary functions and
callback registers inside the main()
function:
SYSTICK_TimerStart();
ext_usart_init();
USART0_WriteCallbackRegister(USART0_WriteEventHandler, (uintptr_t)NULL);
USART0_ReadCallbackRegister(USART0_ReadEventHandler, (uintptr_t)NULL);
RTS_DISABLE();
USART0_Read(&rxBuffer, RX_BUFFER_SIZE);
USART0_Write(&txBuffer, TX_BUFFER_SIZE);
Figure 5-60. Initialization of
Modules
- Add the hardware handshaking
configuration logic inside the
while
loop in the main()
function:SYSTICK_DelayUs(500U);
if(USART0_writeStatus == true)
{
USART0_writeStatus = false;
//Transmit received bytes from EDBG
USART0_Write(&txBuffer, TX_BUFFER_SIZE);
}
if(USART0_readStatus == true)
{
USART0_readStatus = false;
//Receive transmitted bytes from EDBG
RTS_DISABLE();
USART0_Read(&rxBuffer, RX_BUFFER_SIZE);
}
Figure 5-61. Adding the Application
Logic
Figure 5-62. SAM E70 Xplained Ultra –
Hardware Handshaking Output