cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot run STHS34PF80TR sensor at full speed over SPI bus.

LMehm
Associate II

Hello!

We are using STHS34PF80 IR sensor and STM32L031F6 processor in our IR motion sensor device.

In STHS34PF80 datasheet is said that SPI clock speed could be up to 10 MHz.

But we can achieve clock speeds up to 250 kHz.

Strange think is that we are able to read WHO_AM_I byte at 8 MBit/s, but InfraRedPD library doesn't work.

It works at speeds up to 250 kBit/s.

Here is our read function:

void ReadSensor(int16_t *ambientTemp, int16_t *objectTemp)
{
uint8_t pTxData[5];
uint8_t pRxData[5];
uint16_t tObject=0;
uint16_t tAmbient=0;
 
pTxData[0]=(0x27|0x80); //Read TObjH
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, pTxData, 1, 1000);
HAL_SPI_Receive(&hspi1, pRxData, 1, 1000);
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_SET);
tObject|=(uint16_t)pRxData[0];
tObject<<=8;
 
pTxData[0]=(0x26|0x80); //Read TObjL
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, pTxData, 1, 1000);
HAL_SPI_Receive(&hspi1, pRxData, 1, 1000);
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_SET);
tObject|=(uint16_t)pRxData[0];
 
pTxData[0]=(0x29|0x80); //Read TAmbH
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, pTxData, 1, 1000);
HAL_SPI_Receive(&hspi1, pRxData, 1, 1000);
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_SET);
tAmbient|=(uint16_t)pRxData[0];
tAmbient<<=8;
 
pTxData[0]=(0x28|0x80); //Read TAmbL
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, pTxData, 1, 1000);
HAL_SPI_Receive(&hspi1, pRxData, 1, 1000);
HAL_GPIO_WritePin(GPIOA, SPI_NSS, GPIO_PIN_SET);
tAmbient|=(uint16_t)pRxData[0];
 
*ambientTemp=tAmbient;
*objectTemp=tObject;
}

Would you please advice!

4 REPLIES 4
AScha.3
Chief II

1. how you set cpha+cpol ? i think, your IR chip wants: cpol hi + cpha 2 edge

AScha3_0-1696146494426.png

2. basically you can read 4 values in about 0,5ms at 250k speed;

IR update rate is 1...10Hz typ. , so 100...1000ms between accesses.

so need 0,5% cpu time at 250k rate -- what you want to gain here ? 

If you feel a post has answered your question, please click "Accept as Solution".
LMehm
Associate II

Hi!

Thank you for your reply.

It doesn't work with cpol hi + cpha 2 edge @8 Mbit/s?!

TDK
Guru

The SPI can run just fine at 8 MHz, as you've seen by reading the WHO_AM_I register. Something else is happening here.

> InfraRedPD library doesn't work.

What isn't working about it? As @AScha.3 suggests, it could very well be that you are trying or expecting to read too often and the CPU can't keep up.

The code you presented doesn't appear to have any issues.

If you feel a post has answered your question, please click "Accept as Solution".
LMehm
Associate II

Hi!

We are setting ODR to 4Hz and I think this is not a problem for the processor to read necessary bytes.

But when I set SPI speed to 8 Mbit/s or any speed above 250kBit/s InfraRedPD library stops detecting movements?!

Also I am printing data_out.t_obj_change and it varies too small to exceed the movement threshold.

Library begins to work again when I set SPI speed to 250 kBit/s or less.