This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI_Master : Expecting same result in SPI Mode 0 and 3 but it differs

In the sensor datasheet it says one can use SPI_Mode 0 or 3 (doesn't say that there is anything to do to switch between them).

I connected MISO from the DK with SDO from the Sensor and MOSI with SDI

image description

I tried all 4 CPHA/CPOL combinations and 2 should give me the same result.. but they all differ! (Of course I chose a coefficient that should be constant (and with no change in spi mode but just resetting to get the result again it is.).

RX from left to right: reset-command, prom-read-command 0xA6, prom read results

ActiveLow + Trailing : FE FE 92 93 
ActiveLow + Leading : FF FF C9 49 
ActiveHigh + Leading : FE FE FE C8 
ActiveHigh + Trailing : FF FE FE 87

What am I missing? I used the ble_uart example and added SPI. Of course I tried other speeds too.

Maybe someone with a 100% working SPI Slave could flash, just edit the command and test if the code works?

main.c ble_app_uart.zip

Datasheet of Sensor

  • ActiveLow + Leading and ActiveHigh + Trailing should give you the same results. Could it be that the last bit you receive is some kind of ACK bit, and that if you receive 0xFF it was not acknowledged. And the two other modes give you a false 0xFE because SDO is sampled to late. Problems like this is really hard to debug without a logic analyzer. It could be many things..

  • Due to holidays I won't be able to get access to an logic analyzer before tuesday. Also their support telephone was already shut down. I would really like to have this problem solved asap. As I can't "waste" so much time with simple SPI. But I can't find anything I could have done wrong in the Datasheet :(

    I would like to try to have some delay before pulling ChipSelect high, gonna try to figure it out now.

    I just wrapped delay around this, as I am not 100% sure if this pulls CS high or low..

    nrf_delay_ms(10);
        nrf_gpio_pin_clear(p_spi_instance->pin_slave_select);
        spi_master_send_initial_bytes(p_spi_instance);
    nrf_delay_ms(10);
    

    But it didn't changed anything

  • Of course I made a list of possible combinations from everything I could imagine... spi modes, speeds, commands, sending 1/2/3 bytes at once.. and nothing seemed to work.

    But I just tried it again now with 3bytes at once (prom read command + 2byte read) and this time I got the same results!!! I really don't know what my sleepy mind missed yesterday evening but I will forgive him if it finally works now! ActiveLow+Trailing or High+Leading. Gonna test it some more now..

    Seem to work so far.

    Conclusion: This sensor ( MS5803 ) is not as cool with getting deselected in between reading command and the reading itself as i thought...

    This sentence of the datasheet had me confused:

    The CSB pin can be pulled high after the command is sent or after the end of the command execution (for example end of conversion)

    I am still wondering if the reset command in the beginning actually works if I pull CSB high and then wait 3ms and not the other way around.

  • Hi muhkuhns , I like that you do not give up on your problems and mostly try to find the solution yourself. But the coolest part is that you care to post the solution here, that is the most important thing. kudos.

  • Thank you very much for these kind words. Reciprocity is key. Even though I'm afraid the next few weeks I will be mostly taking. (I already have the feeling I would flood the devzone with questions... But I have little to no choice as I got a hard deadline (and many side aspects.. hardware layouting e.g.) and I'm not well grounded with these topics yet). The beginning is always the hardest part.. new development environment, new µC architecture + BLE. But the time I'll answer foreign questions will come!

Related