Adding extra bits when sending instruction to LS7366R

I have a problem with the SPI communication, I send an instruction to read the register but the arduino adds to extra bits like a prefix, so the instruction it's not correct. I don't know why it adds the extra bits. I took a photo of it in the oscilloscope:

The code I'm using is the following:

#include <SPI.h>

const int ss = 10;
const int CLEAR_COUNTER = 0x20;
const int CLEAR_STATUS = 0x30;
const int READ_COUNTER = 0x60;
const int READ_STATUS = 0x70;
const int WRITE_MODE0 = 0x88;
const int WRITE_MODE1 = 0x90;
char str [100];

void setup()
{
SPI.begin();

pinMode(ss, OUTPUT);

Serial.begin(9600);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
Serial.println("New test");
}

void loop()
{
unsigned long num;
digitalWrite(ss, LOW);
SPI.transfer(WRITE_MODE0);
SPI.transfer(WRITE_MODE1);
char data [5];
data [0] = 126;
int i = 1;

for (i;i<5;i++)
{
data [i] = 126;
}

int count[5];

digitalWrite(ss,LOW);      // Begin SPI conversation
SPI.transfer(0x60);                     // Request count
count[1] = SPI.transfer(0x00);           
count[2] = SPI.transfer(0x00);           
count[3] = SPI.transfer(0x00);           
count[4] = SPI.transfer(0x00);          
digitalWrite(ss,HIGH); 

num=0;
for (i=1;i<5;i++){
num = num<<8 + data[i]; //count[i]

}

}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Your topic was MOVED to its current forum category as it is more suitable than the original

there is already a library available for the LS7366R! :slight_smile:
why not its example and see if that works for you.

you can further study the library code if you still want to write your own code :wink:

hope that helps...

Since your oscilloscope picture seems to only show the Received Data pin (MISO) and the Select pin (SS) it is impossible to tell from that what is actually being sent. Please add the MOSI and SCLK pins and show a close-up of the first 8 clocks after the SS goes low.

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