ASF4 IO_Read() not working for SAMD20

Thread Starter

sc0tch

Joined Nov 6, 2018
64
Hey guys. Fairly new to the Atmel software framework, usually use MPLab/PIC devices but for my project I needed to build a UART router capable of connecting 6 UART devices together so I chose a SAMD20J16 chip. So far iv'e configured the drivers using ATMEL start with USART HAL_ASYNC drivers for all USART modules.

Iv'e gotten the device to write to all 6 USART modules and have gotten the read interrupt to trigger but I am unable to read from the usart buffer. For now ive stripped it down to the minimal code possible to try and find out why it's not working, it's probably a simple oversight on my part, but Iv'e been searching the internet for 2 days and all the documentation I can find using the HAL_ASYNC drivers in ASF4 is flaky at best.

Code:
#include <atmel_start.h>


int main(void)
{
    int nRead=0;
    uint8_t rxPData;
   
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();
   
    //DECLARE UART STRUCTURTES
    struct io_descriptor *uartD1;
    usart_async_get_io_descriptor(&USART_0, &uartD1);
    usart_async_enable(&USART_0);
   
    struct io_descriptor *uartP;
    usart_async_get_io_descriptor(&USART_1, &uartP);
    usart_async_enable(&USART_1);
   
   
    struct io_descriptor *uartD3;
    usart_async_get_io_descriptor(&USART_2, &uartD3);
    usart_async_enable(&USART_2);
   
    struct io_descriptor *uartD4;
    usart_async_get_io_descriptor(&USART_3, &uartD4);
    usart_async_enable(&USART_3);
   
    struct io_descriptor *uartS;
    usart_async_get_io_descriptor(&USART_4, &uartS);
    usart_async_enable(&USART_4);
   
    struct io_descriptor *uartD2;io_write(uartP, (uint8_t *) "UART P\r\n", 8);
    usart_async_get_io_descriptor(&USART_5, &uartD2);
    usart_async_enable(&USART_5);
   
    void uartP_callback(const struct usart_async_descriptor *const io_descriptor){
        if(usart_async_is_rx_not_empty(uartP)){
                io_write(uartP, (uint8_t *) "TEST P\r\n", 8);
           
                   
                    nRead=io_read(uartP,&rxPData,6);
                   
                    io_write(uartP,&rxPData,nRead);
        }
                    
       
       
    }
   
    usart_async_register_callback(&USART_1, USART_ASYNC_RXC_CB, uartP_callback);
    
    /* Replace with your application code */
    while (1) {
       
       
       
       
       
       
       
   
       
       
    }

   
   

}
The behavior I am getting is any time I send a packet to the mCU it outputs the "TEST P\r\n", but I don't get any output or error from the echo back of IO_READ. Any help is much appreciated!
 
Top