Sensirion / embedded-uart-sps

Embedded UART Driver for Sensirion Particulate Matter Sensors - Download the Zip Package from the Release Page
https://github.com/Sensirion/embedded-uart-sps/releases
BSD 3-Clause "New" or "Revised" License
44 stars 24 forks source link

UART HAL Recieve #82

Closed angan-code closed 3 years ago

angan-code commented 3 years ago

Hi,

I am trying to communicate the SPS30 with UART. I am able to transmit command using your driver files. for ex. if i send data for start measurement, i am able to hear the sensor switched on and running. int16_t sensirion_uart_tx(uint16_t data_len, const uint8_t data) { uint16_t len; len = UARTPuts(&gPM, (uint8_t) data, data_len); if(len == data_len) return data_len; return 0; }

Problem. I have issue recieving the full frame from the sensor. During debugging, i recieive 0x7e and remaining 0s in the Rxbuffer. i recieve the char in a call back function from interrupt and copy the data into the buffer needed.

Callback function void PM_ByteReceived(void){

char    c;
uint8_t status;

while (UARTReadable(&gPM))
{
    c = UARTGetc(&gPM, &status);
    //HAL_Delay(1000);

    if (status == 0)
    {
        PM_RxBuffer[receivedBytesPM++] = c;
        HAL_Delay(1000);
    }
}

}

from the usart implementation function int16_t sensirion_uart_rx(uint16_t max_data_len, uint8_t* data) {

if(max_data_len == 0)
    return -1;

memcpy((uint8_t*)data, PM_RxBuffer, max_data_len);
return sizeof(data);

}

I recieve 7E and 0 and Uartreadable gets out of the loop in the callback function. bool UARTReadable(sUART* uart) { if (uart->initialized) {

uint8_t uartindex = FindUARTIndex(uart);

if (uartindex == 0xFF)
{
  return false;
}

return ((__HAL_UART_GET_FLAG(&uart->huart, UART_FLAG_RXNE) == true) || (overflowBuffer[uartindex].dataExist));

} else { return false; } }

angan-code commented 3 years ago

Error is SENSIRION_SHDLC_ERR_ENCODING_ERROR

rnestler commented 3 years ago

i recieve the char in a call back function from interrupt and copy the data into the buffer needed.

I'd advise to get it working with a blocking/synchronous implementation first and then switch to an interrupt based implementation. Getting things right with interrupts is much harder.