[SOLVED] Cannot get ADS1256 + STM32F103 board to work - Page 1
Forum section: electronics / general

author: floxia
author_rank: Contributor
timestamp: July 18, 2023, 08:15:07 am
content: Hello there!I have been playing around with this board for a few months, but I had no luck while trying to communicate between the STM32 and the ADS1256; I have to admit that although I have squeezed my brain quite a fair bit, I do not seem to understand how to write a code to communicate via SPI. I know what should happen to the registers based on what the datasheets specify, but I have no idea how to make that happen in the code.Said so, I have been relying on existing libraries for the ADS1256 with the hope that they are correct (I am using the STM32 library for the Arduino IDE), but so far, I had no luck.At first, I had the feeling that since the board uses the SPI2 (as it is possible to see from the schematic), I was not communicating through the right SPI channel, but even that was not successful.I do not really have a code that I have made that I can show, but I could show what I did modify in the existing code to initialise the correct SPI channel if that helps.I understand it is a long shot, but is there a code I could use to test the communication between the STM32 and the ADS1256 simply to check that the board is working correctly so that I can put some extra effort into getting the board to work? Because at this stage, I am confused and unsure if the board is faulty or my brain is.Please be patient; I am new to this, but I would like to learn more to improve my skills!

author: liaifat85
author_rank: Regular Contributor
timestamp: July 18, 2023, 08:35:02 am
content: You can post this problem to the ARM forum.https://community.arm.com/

author: darkspr1te
author_rank: Frequent Contributor
timestamp: July 18, 2023, 08:42:30 am
content: In arduino you have to specify which spi it uses or they default to spi1 , often it done at the top where you declare the spieg.Code:SPI.setMOSI(PB15);SPI.setMISO(PB14);SPI.setSCLK(PB13);SPI.begin();Or:SPIClass SPI_2(PB15,PB14,PB13);SPI_2.begin();without knowing exactly which libs you are using I can only guess

author: darkspr1te
author_rank: Frequent Contributor
timestamp: July 18, 2023, 08:52:44 am
content: and here's some source code for that exact board ,https://curiousscientist.tech/blog/ads1256-arduino-stm32-sourcecode

author: floxia
author_rank: Contributor
timestamp: July 18, 2023, 09:29:13 am
content: Quote from: darkspr1te on July 18, 2023, 08:52:44 amThanks for suggesting this, although I have already used used the code and updated it to this:Code:#include <SPI.h> //SPI comunicationvoid setup(){Serial.begin(115200);delay(1000);initialize_ADS1256();delay(1000);reset_ADS1256();userDefaultRegisters();printInstructions();attachInterrupt(digitalPinToInterrupt(PB10), checkDReady, FALLING); //FALLING - DRDY goes low}//--------------------------------------------------------------------------------//Variables//Booleansvolatile boolean dataReady; //It is very important to have it defined as volatile!double VREF = 2.50; //VREF for converting the raw data to human-readable voltage//Pinsconst byte CS_pin = PB12;//goes to CS on ADS1256const byte DRDY_pin = PB10; //goes to DRDY on ADS1256const byte RESET_pin = PB11; //goes to RST on ADS1256andCode:#include <SPI.h> //SPI comunicationvoid setup(){Serial.begin(115200);delay(1000);initialize_ADS1256();delay(1000);reset_ADS1256();userDefaultRegisters();printInstructions();attachInterrupt(digitalPinToInterrupt(PB10), checkDReady, FALLING); //FALLING - DRDY goes low}//--------------------------------------------------------------------------------//Variables//Booleansvolatile boolean dataReady; //It is very important to have it defined as volatile!double VREF = 2.50; //VREF for converting the raw data to human-readable voltage//Pinsconst byte CS_pin = PB12;//goes to CS on ADS1256const byte DRDY_pin = PB10; //goes to DRDY on ADS1256const byte RESET_pin = PB11; //goes to RST on ADS1256But it did not work, that is why I was looking for a code to test the communication in order to see if there is anything happening between the microcontroller and the ADC.

author: floxia
author_rank: Contributor
timestamp: July 18, 2023, 09:56:25 am
content: I did another test with the code above and the code stops at the following function at the line SPI.transfer(0xFE); //Reset command:Code:void reset_ADS1256(){SPI.beginTransaction(SPISettings(1920000, MSBFIRST, SPI_MODE1)); // initialize SPI with clock, MSB first, SPI Mode1digitalWrite(CS_pin, LOW);delayMicroseconds(7);SPI.transfer(0xFE); //Reset commanddelay(2); //Minimum 0.6ms required for Reset to finish.SPI.transfer(0x0F); //Issue SDATAC (any 8-bit value would complete the RESET command)delayMicroseconds(100);digitalWrite(CS_pin, HIGH);SPI.endTransaction();}EDIT:I have finally managed to get it to work; I did not know that there was a menu to select the specific version of the STM32F1, which was set to STM32F103C6 instead of the correct STM32F103C8