Page 1 of 1

Nucleo H743ZI multiple SPI slaves CS irregularity

Posted: Tue Mar 24, 2020 1:52 pm
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);

  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: ");

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

  SPI.transfer(CS_3, 0x80, SPI_CONTINUE);
  readData[0] = SPI.transfer(CS_3, 0x00, SPI_LAST);
  Serial.print("Manual read out S3: ");
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!

Re: Nucleo H743ZI multiple SPI slaves CS irregularity

Posted: Wed Mar 25, 2020 9:07 am
by fpiSTM
First did you read the Wiki:

Re: Nucleo H743ZI multiple SPI slaves CS irregularity

Posted: Thu Mar 26, 2020 7:28 pm
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?