0

I am using ATSAMD21 microcontroller as a slave which is connected to a Master MCU(ESP32) through UART. OS- For ATSAMD21 - FreeRTOS (IDE- MPLAB) and for ESP32 (FreeRTOS).

One of my application in SAMD21 controller is to read and write in a "while" loop in continuous manner. for ex-

while(1)
{
    memset(ch,0,2);
    SERCOM3_USART_Read(ch,2); 
    SERCOM3_USART_Write(th,2);
}

Note- Here 'ch' and 'th' are char[]. the issue what I am facing here - on reading it should not wait for the interrupt and should perform the next instruction which is "write". But here it is waiting till the master controller (ESP32) have send any character to the SAMD21 and then it perform the next "write" operation and again wait for the next message to get read.

I have changed something into the driver layer-

https://drive.google.com/file/d/1rNHuQp0irYJdlRmpt5qk-6NeG3qgAWmx/view?usp=sharing

Here I changed line no- 370 from-

while((SERCOM3_REGS->USART_INT.SERCOM_INTFLAG & SERCOM_USART_INT_INTFLAG_RXC_Msk) == 0U)
{
     /* Do nothing */
}

to-

if((SERCOM3_REGS->USART_INT.SERCOM_INTFLAG & SERCOM_USART_INT_INTFLAG_RXC_Msk) == 0U)
{
     /* Do nothing */
}

In this my problem is resolved but I am able to take only one byte of data at a time. If I am sending more then 1 byte it is taking series of last data.

How can I run my function in continuous manner for reading and writing through UART in this.

  • Use DMA instead. – Lundin Oct 21 '21 at 09:50
  • @Lundin In my FW there is lot of things which is happening through UART. Including DMA will take more memory and I have to change most of things for DMA. I know this can be solution but not efficient in my case. Can we do anything in driver side for UART to make it work. I think it is general in all the controllers as I am using ESP32 as master MCU and it is working fine in that. – Murlidhar Roy Oct 21 '21 at 10:19
  • 1
    Yes you can implement an old school UART driver with ring buffers, separate for tx and rx. Not that the ASF bloatware is not a solution to any problem. At best you can look at some register setups from there when you write your own code. – Lundin Oct 21 '21 at 10:22
  • Thanks. Instead of writing own code, can we edit anything in the drivers which is available from Microchip (I already posted the link to download). Writing and validating the entire driver will take more time then this. – Murlidhar Roy Oct 21 '21 at 10:53
  • It depends on what quality standards you are aiming for - if you just want to produce some Arduino barf hobbyist project, then it might be ok so use ASF. But I would never use it in professional production code since it's a very badly written library. Far from MISRA-C compliant and so on. You can peek at it for reference and maybe even dare to use their register maps, but that's about it. – Lundin Oct 21 '21 at 11:01

0 Answers0