Nucleo H743ZI multiple SPI slaves CS irregularity

All about boards manufactured by ST
Post Reply
steamguy
Posts: 2
Joined: Tue Mar 24, 2020 12:50 pm

Nucleo H743ZI multiple SPI slaves CS irregularity

Post by steamguy »

Hi together,

I am having trouble transferring my Due Code to the Nucleo H743ZI.
To read out three BMA280 accelerometers with the same SPI instance, I need to manually configure the CSs.
By reading out register 0x00 ChipID I can evaluate the connection: Two of the CS are working, the third yields an irregular value which I can not figure out. While CS_1 and CS_2 are constantly yielding the fixed value "251", CS_3 often reveives false values, e.g. 246 or 247, but not constantly. Running the same lines again can lead to these outputs:

Code: Select all

S3 246
S3 246
S3 251
S3 251
S3 251
S3 246
S3 251
S3 251
S3 251
When swopping pins the other sensores yield resp. values, so it seems to be PIN-related. My guess is that either the settings are incorrect, or the pin is not usable in the first place.

Pins I've tried for CS_3 are:
  • PF12, since it is a general I/O pin
  • PA0, since the other pins on timer functions work as well
  • PA4, since it is a designated CS pin, although for SPI_B
It has to be said that I am relatively new to programming in general and it is possible that you shake your head because of my stupidity. However it would be nice to get help with the set up anyway.

This is the part of the code I am having trouble with:

Code: Select all

#include <SPI.h>

const uint8_t CS_1 = PD14;
const uint8_t CS_2 = PD15;
const uint8_t CS_3 = PA0;
byte readData[6];

void setup() {
  pinMode(CS_1, OUTPUT);
  pinMode(CS_2, OUTPUT);
  pinMode(CS_3, OUTPUT);
  
  Serial.begin(115200);

  SPI.begin();
  SPI.beginTransaction(CS_1, SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));
  SPI.beginTransaction(CS_2, SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));
  SPI.beginTransaction(CS_3, SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));

 //Reading out register 0x00 in read mode --> 0x00 | 0x80 
  SPI.transfer(CS_1, 0x80, SPI_CONTINUE);
  readData[0] = SPI.transfer(CS_1, 0x00, SPI_LAST);
  Serial.print("Manual read out S1: ");
  Serial.println(readData[0]);

  SPI.transfer(CS_2, 0x80, SPI_CONTINUE);
  readData[0] = SPI.transfer(CS_2, 0x00, SPI_LAST);
  Serial.print("Manual read out S2: ");
  Serial.println(readData[0]);

  SPI.transfer(CS_3, 0x80, SPI_CONTINUE);
  readData[0] = SPI.transfer(CS_3, 0x00, SPI_LAST);
  Serial.print("Manual read out S3: ");
  Serial.println(readData[0]);
}
This code would print 251 for CS_1 and CS_2 continuously, whereas for CS_3 it prints either 251 or 246.

Any tips, links, documentations, ... would be great, thanks for you help!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Nucleo H743ZI multiple SPI slaves CS irregularity

Post by fpiSTM »

Hi,
First did you read the Wiki:
https://github.com/stm32duino/wiki/wiki/API#spi
steamguy
Posts: 2
Joined: Tue Mar 24, 2020 12:50 pm

Re: Nucleo H743ZI multiple SPI slaves CS irregularity

Post by steamguy »

Yes, I read the Wiki. I had trouble initializing a new instance with SPIClass at first. Since I have three CS to add anyway I reckon that is not my problem here and so I just stocked eith SPI 1.
Additionally, since two of the three sensors are responding as expected and switching pins transfer the behavior to the other sensor, I figure the Pin of the board is the problem. I was not able to find detailed documentation about SPI communication on the board / with the processor either.

Is it possible that the clock speed has to be set differently for different pins?
Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”