Closed Anzal3c3 closed 1 year ago
{98}{FF}{09}{20}{36}{02}{00}{00}{7E}{00}{00}{02} this is the response i am getting from the sensor when its connected to the mcu when i send start measurement command . when i send the command the fan is turning on but the response is different than in the data sheet
/*
int i=0; /*
/**
uint8_t datas[100];
int16_t sensirion_uart_select_port(uint8_t port) { return 0; }
/**
/**
/**
Return: Number of bytes sent or a negative error code / int16_t sensirion_uart_tx(uint16_t data_len, const uint8_t data) { // TODO: implement
HAL_UART_Transmit_DMA(&huart5,(uint8_t*) data, data_len);
//HAL_UART_Transmit(&huart2,(uint8_t*) data, data_len, 100);
return data_len; }
/**
Return: Number of bytes received or a negative error code / int16_t sensirion_uart_rx(uint16_t max_data_len, uint8_t data) { // TODO: implement
int32_t bytes_received = 0; //HAL_UART_Receive_IT(&huart5,(uint8_t*) data, max_data_len);
HAL_StatusTypeDef status = HAL_UART_Receive_IT(&huart5,(uint8_t*) data, max_data_len);
if (status == HAL_OK) {
bytes_received = max_data_len - huart5.RxXferCount;
}
return bytes_received;
}
/**
@param useconds the sleep time in microseconds */ void sensirion_sleep_usec(uint32_t us) {
// TODO: implement HAL_Delay(us); }
Hi @Anzal3c3
For STM we currently don't have a UART sample implementation or a working setup. I therefore try to explain how the protocol works so you better understand the results you get.
The UART interface implements a Sensirion protocol (SHDLC) on top of uart which introduces frames for a more reliable communication.
Please note that UART will not necessary read all the data at once. This depends on the implementation of the underlying library.
A very simplified explanation of the protocol: Each frame has at most 255 bytes of data and is encapsulated in the start/stop byte (0x7E)
to avoid conflicts, there are the following byte stuffings
0x7E => 0x7D, 0x5E
0x7D => 0x7D, 0x5D
0x11 => 0x7D, 0x31
0x13 => 0x7D, 0x33
A message (MOSI) has the following parts
Address (1 byte) | Command (1 byte) | Lengh (1 byte) | Data (Lenght bytes) | Checksum (1 byte)
The response (MISO)
Address (1 byte) | Command (1 byte) | State (1byte) | Lengh (1 byte) | Data (Lenght bytes) | Checksum (1 byte)
You should also be able to find this information in the SPS30 datasheet.
If the answer you receive from the module is not starting with 0x7E and stopping with 0x7E you most probably have not read all the data.
Note Wake-up command is 0x11 (which is encoded to 0x7D 0x31
The sensor answers with (It looks like you duplicated the same message, or read it twice):
{7E}{00}{7D}{31}{43}{00}{AB}{7E}
which is
frame start => 0x7E
Address => 0x00
Wake_up => 0x7D 0x31 => 0x11
State => 0x43
Length => 0x00
Checksum => 0xAB
frame end => 0x7E
so for the wake-up command the response makes sense. Btw. the state 0x43 means "Command not allowed in current state" because the sensor is already awake. This error you can ignore.
Since the fan turns on, it looks like the transmission of the start command was successful. The answer you get however doesn't look complete.
{98}{FF}{09}{20}{36}{02}{00}{00}{7E}{00}{00}{02}
The MOSI data sent to the sensor should look as follows
frame start => 0x7E
Address => 0x00
Start measurement => 0x00
length => 0x2 (2 sub-command values are sent: 0x01 and 0x03)
data0 => 0x1
data1 => 0x3
Checksum => 0xF9
frame end => 0x7E
The expected answer is an empty frame, that looks as follows
frame start => 0x7E
Address => 0x00
Start measurement => 0x00
State => 0x00
Length => 0x00
Checksum => 0xFF
frame end => 0x7E
The data you read, looks like it contains the MOSI frame at the end. So something is wrong there. I suspect, the problem is that after each send and read you need to flush the UART buffer to make sure you get the recent data. Also make sure that you read all the data from the buffer within a certain timeout if you still receive incomplete messages.
Let me know if my answer was helpful
@psachs hey thanks for reaching out. it worked for me
HI i am using stm32l4XX microcontroller to read the data from the sensor. It outputs sensor probing failed what could it possibly mean. Is it because of anything wrong with the data being sent or being received?
{7E}{00}{7D}{31}{43}{00}{AB}{7E}{7E}{00}{7D}{31}{43}{00}{AB}{7E} this one is the mosi out that i get from the sensor when is send wakeup instruction