Coder Social home page Coder Social logo

Comments (14)

rnestler avatar rnestler commented on July 20, 2024

Hi @olirehacek

Which HAL libraries do you mean? Do you have a link to a description from ST?

from embedded-uart-sps.

oliexe avatar oliexe commented on July 20, 2024

Hi @olirehacek

Which HAL libraries do you mean? Do you have a link to a description from ST?

Hi @rnestler , appreciate the fast reply.

I mean standard STMicroelectronics HAL Libraries that are supplied by the vendor together with CubeMX Code Initialization Software. I have a Nucelo Development Board and just trying to slap together simple air quality measuring device into our office.

I have managed to send all the commands to the sensors and it works perfectly, but receiving the data is a problem. My receiving buffer is always filled with zeros.
I am totally new to the embedded developing so in case I am doing something completely stupid I'm sorry :D

uint8_t buf_read[6] = { 0x7e, 0x00, 0x03, 0x00, 0xfc, 0x7e };
 
HAL_UART_Transmit(&huart2, buf_read, 8, 1000);
 
for(int i = 0 ; i < 100 ; i++) //Wait for start byte 
{		
    HAL_UART_Receive(&huart2, (uint8_t *)RxBuffer, 1, 1000);
    if (RxBuffer[0] == 0x7E)
        break;
}

//Get rest of packet
HAL_UART_Receive_DMA(&huart1, RxBuffer, 50);

from embedded-uart-sps.

abrauchli avatar abrauchli commented on July 20, 2024

Hi @olirehacek - when you get the receive buffer working it should be really easy to create an implementation for this generic driver by editing:

https://github.com/Sensirion/embedded-uart-sps/blob/master/embedded-uart-common/sensirion_uart_implementation.c

Is it a typo that you wait for 0x7e on huart2 but call Receive on huart1? How are those objects initialized?

//Get rest of packet

HAL_UART_Receive_DMA(&huart1, RxBuffer, 50);

from embedded-uart-sps.

abrauchli avatar abrauchli commented on July 20, 2024

@olirehacek I'm curious if you got it working and if so, would you provide us with a working sample (pull-request welcome)?

from embedded-uart-sps.

oliexe avatar oliexe commented on July 20, 2024

@olirehacek I'm curious if you got it working and if so, would you provide us with a working sample (pull-request welcome)?

Hi. I am out of the office until Tuesday. Hopefully, I can get it running by the end of the week - i will post some results by then.

from embedded-uart-sps.

rnestler avatar rnestler commented on July 20, 2024

@olirehacek Did you find some time to test again?

from embedded-uart-sps.

Shubhanshu2student avatar Shubhanshu2student commented on July 20, 2024

Hello there,
I have got this sensor in the past few days, and I'm trying to get it implemented with STM32F030R8 discovery board using USART.
Firstly I've tried to get the Serial ID with the given SHDLC driver, transmission buffer is correct while receiving sensor is not responding with any data byte.
Any help is appreciated.
Below is my rx and tx functions.

uint8_t Temp = 0,rx_buff[100];

void USART2_IRQHandler(void)
{
  uint8_t ind=0;
  USART_ClearITPendingBit(USART2, USART_IT_ORE);
  if((USART_GetITStatus(USART2,USART_IT_RXNE))==SET )
  {    
    Temp = ((USART_ReceiveData(USART2))&0xff);
    rx_buff[ind++] = Temp;
    if(ind >= (sizeof(rx_buff)-1))
      ind=0;
    USART_ClearITPendingBit(USART2,USART_IT_RXNE);
  }
}

uint16_t sensirion_uart_tx(uint16_t length, uint8_t *tx_buff)
{
  uint8_t idx = 0;
  for(idx = 0; idx < length; idx++)
  {
    uint8_t tx_data = *tx_buff++;
    USART2->TDR = tx_data;
    USART_ClearITPendingBit(USART2,USART_ISR_TC);
  }
  if(idx == length)
    return idx;
  else
    return -1;
}

uint8_t rx_buff[100];
uint16_t sensirion_uart_rx(uint16_t max_data_len, uint8_t *data)
{
  uint8_t data_buff[100];
  if(max_data_len == 0)
    return -1;
  memcpy(data_buff,rx_buff,max_data_len);
  data = data_buff;
  return sizeof(data_buff);
}

from embedded-uart-sps.

rnestler avatar rnestler commented on July 20, 2024

Firstly I've tried to get the Serial ID with the given SHDLC driver, transmission buffer is correct while receiving sensor is not responding with any data byte.

Can you verify with a logic analyzer or oscilloscope what is happening on the bus?

Below is my rx and tx functions.

The implementation doesn't look quit correct, see my comments:

    uint8_t tx_data = *tx_buff++;
    USART2->TDR = tx_data;
    // Here you should probably wait for the date to get transmitted, or does USART_ClearITPendingBit do that?
    USART_ClearITPendingBit(USART2,USART_ISR_TC);

The IRQHandler will just override rx_buf[0] with every byte received.

void USART2_IRQHandler(void)
{
  uint8_t ind=0; // index is always 0 when the IRQ gets called
  USART_ClearITPendingBit(USART2, USART_IT_ORE);
  if((USART_GetITStatus(USART2,USART_IT_RXNE))==SET )
  {    
    Temp = ((USART_ReceiveData(USART2))&0xff);
    rx_buff[ind++] = Temp;
    if(ind >= (sizeof(rx_buff)-1))
      ind=0;
    USART_ClearITPendingBit(USART2,USART_IT_RXNE);
  }
}

The sensirion_uart_rx function just copies to a local buffer and not to the target buffer. Also you can't know how many bytes there are in the rx_buff.

uint8_t rx_buff[100];
uint16_t sensirion_uart_rx(uint16_t max_data_len, uint8_t *data)
{
  uint8_t data_buff[100];
  if(max_data_len == 0)
    return -1;
  memcpy(data_buff,rx_buff,max_data_len); // this just copies to the local buffer
  data = data_buff; // this doesn't write to the target buffer, just reassign the pointer locally
  return sizeof(data_buff); // this will always return 100
}

Isn't there an UART library available for your platform? This should handle all the low level stuff like interrupt handling for you. Maybe try using the "STMicroelectronics HAL Libraries" like @olirehacek did.

from embedded-uart-sps.

Shubhanshu2student avatar Shubhanshu2student commented on July 20, 2024

thanks for your reply, surely I'll check things out and update...
About libraries, I'm using STM Std Peripheral Libraries, to learn more in deep about the peripheral programming.

from embedded-uart-sps.

Shubhanshu2student avatar Shubhanshu2student commented on July 20, 2024

hello there,
I got the sensor working giving me the measured values, Now I'm having some testing issues,

  1. How we can verify the values are correct?
  2. On testing with Air purifier and Sensor in a closed cardboard box the sensor was giving me some constant repeating values between 9.xxxx - 6.xxxx for all the parameters.
  3. If we are keeping the sensor with air purifiers will it give me values in Zeros?

from embedded-uart-sps.

Shubhanshu2student avatar Shubhanshu2student commented on July 20, 2024

The given link is having a video in which I'm getting the data from the sensor. Are these values correct?
If not, suggest the improvement I need to do.
https://drive.google.com/open?id=1_k3cfPWxw5sNjZvufEVvvn36u5UUYHJD

from embedded-uart-sps.

sisanche avatar sisanche commented on July 20, 2024

@Shubhanshu2student while opening the google drive link showing an error.
Could you please post the link or is it possible to share the source files?

from embedded-uart-sps.

angan-code avatar angan-code commented on July 20, 2024

@Shubhanshu2student can you share the working code for sps30 uart rx and handler function? I am also kind of stuck with recieving the first byte and others as zeros.

from embedded-uart-sps.

rnestler avatar rnestler commented on July 20, 2024

I'll close this, since it isn't really an issue with the driver, but just with implementing UART for a specific platform. I advice to read the official documentation from ST about UART.

from embedded-uart-sps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.