cancel
Showing results for 
Search instead for 
Did you mean: 

How can I read serial messages using AEK-MCU-C4MLT1 and SPC5 studio?

Simone882
Associate II

I am currently working on a project where I am using the serial communication. I am using an AEK-MCU-C4MLT1, with SPC5 studio on a windows PC. In particular, I am capable to transmit data but not to receive data. I tried also by enabling the interrupt, either for the transmission and the reception, and I found out that the program enters in the interrupt each time I call the function "sd_lld_read", even if I send no data externally (from docklight). By sending data from docklight, and looking at the rx_buffer I am not able to read anything.

I attach the relevant part of the code here:

int main(void) {

/* Initialization of all the imported components in the order specified in

the application wizard. The function is generated automatically.*/

componentsInit();

/* Uncomment the below routine to Enable Interrupts. */

irqIsrEnable();

sd_lld_start(&SD1,&serial_config_UART);

sd_lld_read(&SD1, (uint8_t*)aux_rx, 1000);

memset(aux_rx,0,sizeof(aux_rx));

/* Application main loop.*/

for ( ; ; )

{

sprintf(aux_tx,"ATE1\r\n");

sd_lld_write(&SD1,(uint8_t *)aux_tx, (uint16_t)(strlen(aux_tx)));

osalThreadDelayMilliseconds(5000);

}

void rxreceive(SerialDriver *sdp)

{

(void)sdp;

}

void txreceive(SerialDriver *sdp)

{

(void)sdp;

pal_togglepad(PORT_F,10);

}

Do you have any idea of what do I have to do in order to receive data and correctly read data? Do you know if I have to call another function in the interrupt?

Thanks in advance,

Simone

1 ACCEPTED SOLUTION

Accepted Solutions
Simone882
Associate II

I managed to resolve the issue by replacing the original "spc5xx_serve_rxi_interrupt" driver (inside serial_lld.c) with this one:

static void spc5xx_serve_rxi_interrupt(uint32_t isdp) {

 SerialDriver *sdp = (SerialDriver *) isdp;

 uint16_t sr = sdp->linflexlp->UARTSR.R;

 sdp->linflexlp->UARTSR.R = (uint16_t)(SPC5_UARTSR_NF | SPC5_UARTSR_DRF | SPC5_UARTSR_PE0);

 if ((sr & SPC5_UARTSR_DRF) == SPC5_UARTSR_DRF) {

 if(sdp->config->api_mode != SPC5_LIN_API_MODE_BUFFERED_IO) {

  *sdp->rx_buf = (uint8_t)sdp->linflexlp->BDRM.B.DATA4;

  //sdp->rx_buf++; // opistara 2021-02-17

  sdp->linflexlp->UARTSR.R = (uint16_t)SPC5_UARTSR_RMB;

  //sdp->rx_len--; // opistara 2021-02-17

  sdp->rx_len = 0; // opistara 2021-02-17

  if (sdp->rx_len == 0UL) {

  //sdp->linflexlp->UARTCR.B.RXEN = 0; // opistara 2021-02-17

  //sdp->linflexlp->LINIER.B.DRIE = 0; /* Interrupts disabled. */ // opistara 2021-02-17

  if (sdp->linflexlp->UARTCR.B.TXEN == 0UL) {

   sdp->linflexlp->LINIER.R &= ~((uint16_t)(SPC5_LIN_INTERRUPTS));

  }

  /* Call the related callback.*/

  if (sdp->config->rx_end_cb != NULL){

   sdp->config->rx_end_cb(sdp);

  }

  SPC5_LIN_RX_DONE(sdp);

  }

 } else {

  *sdp->rx_write_ptr = (uint8_t)sdp->linflexlp->BDRM.B.DATA4;

  sdp->rx_write_ptr++;

  if (sdp->rx_write_ptr == sdp->rx_end_ptr) {

  sdp->rx_write_ptr = sdp->rx_buffered_io;

  }

  if (sdp->rx_write_ptr == sdp->rx_read_ptr) {

  sdp->rx_read_ptr++;

  if (sdp->rx_read_ptr == sdp->rx_end_ptr) {

   sdp->rx_read_ptr = sdp->rx_buffered_io;

  }

  }

 }

 }

}

and it worked very well for me.

Regarding the configuration "serial_config_UART", I used this one:

SerialConfig serial_config_UART = {

 115200,

 SD_MODE_8BITS_PARITY_NONE,

 SPC5_LIN_API_MODE_ASYNCHRONOUS,

 tx_callback,

 rx_callback,

 FALSE,

 NULL,

 0,

 NULL 

};

I hope that this will help you!

Regards,

Simone

View solution in original post

5 REPLIES 5
ODOUV.1
ST Employee

Hello,

would you please show me your structure "serial_config_UART" ?

Best Regards.

Simone882
Associate II

Hi,

thanks for the response,

I managed to resolve the issue by modifying the driver of spc5xx_serve_rxi_interrupt

ODOUV.1
ST Employee

Hello,

we are very interested by the fix you found.

Would you please communicate on it ?

Best Regards.

Simone882
Associate II

I managed to resolve the issue by replacing the original "spc5xx_serve_rxi_interrupt" driver (inside serial_lld.c) with this one:

static void spc5xx_serve_rxi_interrupt(uint32_t isdp) {

 SerialDriver *sdp = (SerialDriver *) isdp;

 uint16_t sr = sdp->linflexlp->UARTSR.R;

 sdp->linflexlp->UARTSR.R = (uint16_t)(SPC5_UARTSR_NF | SPC5_UARTSR_DRF | SPC5_UARTSR_PE0);

 if ((sr & SPC5_UARTSR_DRF) == SPC5_UARTSR_DRF) {

 if(sdp->config->api_mode != SPC5_LIN_API_MODE_BUFFERED_IO) {

  *sdp->rx_buf = (uint8_t)sdp->linflexlp->BDRM.B.DATA4;

  //sdp->rx_buf++; // opistara 2021-02-17

  sdp->linflexlp->UARTSR.R = (uint16_t)SPC5_UARTSR_RMB;

  //sdp->rx_len--; // opistara 2021-02-17

  sdp->rx_len = 0; // opistara 2021-02-17

  if (sdp->rx_len == 0UL) {

  //sdp->linflexlp->UARTCR.B.RXEN = 0; // opistara 2021-02-17

  //sdp->linflexlp->LINIER.B.DRIE = 0; /* Interrupts disabled. */ // opistara 2021-02-17

  if (sdp->linflexlp->UARTCR.B.TXEN == 0UL) {

   sdp->linflexlp->LINIER.R &= ~((uint16_t)(SPC5_LIN_INTERRUPTS));

  }

  /* Call the related callback.*/

  if (sdp->config->rx_end_cb != NULL){

   sdp->config->rx_end_cb(sdp);

  }

  SPC5_LIN_RX_DONE(sdp);

  }

 } else {

  *sdp->rx_write_ptr = (uint8_t)sdp->linflexlp->BDRM.B.DATA4;

  sdp->rx_write_ptr++;

  if (sdp->rx_write_ptr == sdp->rx_end_ptr) {

  sdp->rx_write_ptr = sdp->rx_buffered_io;

  }

  if (sdp->rx_write_ptr == sdp->rx_read_ptr) {

  sdp->rx_read_ptr++;

  if (sdp->rx_read_ptr == sdp->rx_end_ptr) {

   sdp->rx_read_ptr = sdp->rx_buffered_io;

  }

  }

 }

 }

}

and it worked very well for me.

Regarding the configuration "serial_config_UART", I used this one:

SerialConfig serial_config_UART = {

 115200,

 SD_MODE_8BITS_PARITY_NONE,

 SPC5_LIN_API_MODE_ASYNCHRONOUS,

 tx_callback,

 rx_callback,

 FALSE,

 NULL,

 0,

 NULL 

};

I hope that this will help you!

Regards,

Simone

ODOUV.1
ST Employee

Tante Grazie Simone,

I will report your fix to R&D Team.

Best Regards.