SPI Issues Attiny84 & ADS131M03

Good afternoon, everyone!
I am doing a student project where I need to get data from a 3 channel ADC ADS131M03 using an Attiny84 microcontroller.

My problem is that I can't read any data from any of the registers, and I can't even understand if the problem is in circuit design or a program code.

Attiny84 -> ADS131M03

MOSI -> DO

MISO -> DI

SCK -> SCLK

CKOUT -> CLKIN

GND -> CS

I switch the CS manually as I use the SPI bus to program the microcontroller as well

I use Arduino IDE for desing code and "Arduino as SPI" as programmer.

Also I used AVRDUDE to program fuses of Attiny84.

In my code I am trying to read 0x00 register and send this data to Serial Port.

#include <tinySPI.h>
#include <SoftwareSerial.h>//  mySerial.begin(1200);

// Definitions
#define rxPin 9
#define txPin 10
SoftwareSerial mySerial(rxPin, txPin);

#define ADCresetPin 2
uint8_t reg = 0x00;

uint32_t spiTransferWord(uint16_t inputData) {
  uint32_t data = SPI.transfer(inputData >> 8);
  data <<= 8;
  data |= SPI.transfer((inputData<<8) >> 8);
  data <<= 8;
  data |= SPI.transfer(0x00);

  return data << 8;
}

uint16_t readSingleRegister(uint8_t reg) {
  uint8_t commandPref = 0x0A;

  // Make command word using syntax found in the data sheet 101a aaaa annn nnnn
  uint16_t commandWord = (commandPref << 12) | (reg << 7);

  uint32_t responseArr[5];

   // Send the command in the first word
  responseArr[0] = spiTransferWord(commandWord);

  // For the next 3 words, just read the data
  for (uint8_t i = 1; i < 5; i++) {
    responseArr[i] = spiTransferWord(0);
  }

  // Save CRC bits
  responseArr[0] = spiTransferWord(0);

  return (responseArr[0] >> 8);  // Extract the 16-bit data from the response
}

void setup() {
  mySerial.begin(1200);
  mySerial.println("Program started");

  pinMode(ADCresetPin, INPUT);

  SPI.begin();
  SPI.setDataMode(SPI_MODE1);
}

void loop() {
  /*reg++;
  if(reg > 23){
    reg = 0;
  }*/

  uint16_t reg_data = readSingleRegister(reg);

  mySerial.print("Register addr: 0x");
  mySerial.println(reg, HEX);
  mySerial.print("Register data: 0x");
  mySerial.println(reg_data, HEX);

  mySerial.println("*****************");
  
  delay(1000);
}

As I understand it, I need to send a 24-bit word with a 16-bit command in it.
Then send any commands to get 5 words of response, and the 6th word should be the register data.

I Programmed CKOUT Fuse of Attiny84 to set(PCINT10/INT0/OC0A/CKOUT) PB2 pin as frequency generator with 1Mhz.

I have a good square 1MHz signal at the CLKIN ADC input.
I attached a photo from the oscilloscope in reply due to forum restriction

Recommended Operating Conditions from datasheet

fCLKIN External clock frequency

+----------------------+------------------+-------------------+-------------------+
| Mode | Minimum (MHz) | Nominal (MHz) | Maximum (MHz) |
+----------------------+------------------+-------------------+-------------------+
| High-resolution mode | 0.3 | 8.192 | 8.4 |
+----------------------+------------------+-------------------+-------------------+

Results in SerialPort with CS of ADC to GND: //some random values

Unfortunately, I only have a 2-channel oscilloscope. Therefore, I will send different pictures of MOSI (CH2) + CSK (CH1) and video of MISO (CH2) + CSK (CH1) measurements.

image
Signal on the MOSI leg of the microcontroller.
I send a 24 bit word command to read register 0x00 (A0 0000) once per second

video with SCLK + MISO Measurements

As I mentioned above, once a second I send a read command in a 24 bit word (0xA0 0000), and after this word I send 4 more words with zeros to complete a 5 word frame, +1 word during which I expect to get a response. However, each time I get different data from ADC, even though the command is the same from time to time.

Please help me figure this out, I don't know what I'm doing wrong anymore.

I'd appreciate any help

Regards, Ihor Shybka

Links:
Attiny84 datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7701_Automotive-Microcontrollers-ATtiny24-44-84_Datasheet.pdf

ADS131M03 datasheet: https://www.ti.com/lit/ds/symlink/ads131m03.pdf?ts=1697316213844&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FADS131M03%252Fpart-details%252FADS131M03IPWR%253Futm_source%253Dgoogle%2526utm_medium%253Dcpc%2526utm_campaign%253Docb-tistore-promo-asc_opn_en-cpc-storeic-google-wwe%2526utm_content%253DDevice%2526ds_k%253DADS131M03IPWR%2526DCM%253Dyes%2526gclid%253DCjwKCAjw-KipBhBtEiwAWjgwrMflfgr14QSMRJuGNAvVbOpBHxupMKuxAdBjheqGRYJKy1bzA7aTYxoCnooQAvD_BwE%2526gclsrc%253Daw.ds

tinySPI libruary description: GitHub - JChristensen/tinySPI: Arduino hardware SPI library for ATtiny44/84, 45/85, 461/861, 2313/4313.


Schematic of my device.

image
1MHz signal at the CLKIN ADC input.

image
Signal on the MOSI pin of the microcontroller on a different scale.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.