how to send 24 bit at once multiple times using SPI for multiple register

Hackscribble:
Try this program, which includes the test function from the other thread and calls it every 3 seconds.

What results do you see on serial monitor and oscilloscope?

Note: you were using SPI mode 2. From the technical note, I think it might need to be mode 0.

I’m testing the code you give and the result is on the oscilloscope at Mode0 is nothing just DC line, on the other hand at the serial monitor
Show
Product codes
0 C6

but when i swich to mode 1 or 2 or 3 the oscilloscope stay the same but the serial monitor
Show
Product codes
4C 63

i attach to you what i see when i use my original code from the oscilloscope.

Hackscribble:
Which output do you mean? SPI output from device back to Mega? Or the output of the device that the register writes are meant to control?

yes the second part which is The output of the device that the register writes are meant to be control.

@AlaaNoah, please do not cross-post. Threads merged.

Thanks for that, @AlaaNoah

I was updating the program in my post while you were testing - sorry about that.

Could you please test again with the latest version.

And can you change the oscilloscope to monitor SPI output from the device back to MISO on the Mega.

Hackscribble:
Thanks for that, @AlaaNoah

I was updating the program in my post while you were testing - sorry about that.

Could you please test again with the latest version.

And can you change the oscilloscope to monitor SPI output from the device back to MISO on the Mega.

i do not see anything when i use this code

Try this. What do you see on serial monitor and oscilloscope?

#include <SPI.h>

void showProductCodes()
{
  Serial.println("Product codes:");
  digitalWrite(SS, LOW);
  SPI.transfer(0xC2);
  byte pCode1 = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  delay(50);
  digitalWrite(SS, LOW);
  SPI.transfer(0xC3);
  byte pCode2 = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  Serial.print(pCode1, HEX);
  Serial.print("   ");
  Serial.println(pCode2, HEX);
}

void showSPIFrameId()
{
  Serial.println("SPI Frame ID:");
  digitalWrite(SS, LOW);
  SPI.transfer(0xFE);
  byte frameID = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  Serial.println(frameID, HEX);
}


void setup (void)
{
  Serial.begin(115200);

  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  SPI.begin ();
  SPI.setBitOrder(MSBFIRST); //We know this from the Data Sheet
  SPI.setClockDivider(SPI_CLOCK_DIV8); // Slow down the master a bit
  SPI.setBitOrder(SPI_MODE0);

  // showSPIFrameId();
}

void loop (void)
{
  showProductCodes();
  delay(3000);  // 3 seconds delay
}

Hackscribble:
Try this. What do you see on serial monitor and oscilloscope?

Hi Hackscribble & Good Morning,

This what the serial monitor show.

Product codes:
0 C6
Product codes:
0 C6

what the oscilloscope show is attach with this repaly

Thanks for that. Could you please test again with this new version.

#include <SPI.h>

void showProductCodes()
{
  Serial.println("Product codes:");
  digitalWrite(SS, LOW);
  SPI.transfer(0xC2);
  byte pCode1 = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  delay(50);
  digitalWrite(SS, LOW);
  SPI.transfer(0xC3);
  byte pCode2 = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  Serial.print(pCode1, HEX);
  Serial.print("   ");
  Serial.println(pCode2, HEX);
}

void showSPIFrameId()
{
  Serial.println("SPI Frame ID:");
  digitalWrite(SS, LOW);
  SPI.transfer(0xFE);
  byte frameID = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  Serial.println(frameID, HEX);
}


void setup (void)
{
  Serial.begin(115200);

  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  SPI.begin ();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  SPI.setDataMode(SPI_MODE0);

  // showSPIFrameId();
}

void loop (void)
{
  showProductCodes();
  delay(3000);  // 3 seconds delay
}

@Hackscribble

This time the serial monitor show.
show

Product codes:
4C 63
Product codes:
4C 63

Oscilloscope attach with this repaly Where
ch1 = CLK
ch2 = chip select
ch3 = input data
ch4 = output data

Hackscribble: Thanks for that. Could you please test again with this new version.

Can please let me know what are you trying exactly looking to see ,other than the chip information?.

I wanted to check that you were getting SPI data back from the chip and that the SPI settings look right.

Those product codes aren’t listed in Technical Note 0897. Have you been able to identify the actual chip you are using? Do you have a datasheet for it?

Then, going back to your original question …

You want to write 16-bit data values to six registers on the chip, is that right?

Ignoring the program code for the moment, what are the register addresses and what are the 16-bit data values you want to write?

Also, can you remove the // from the following statement in the test program, and run it again. No need for screenshot, just want to know what value it prints for SPI Frame ID.

showSPIFrameId();

Hackscribble: I wanted to check that you were getting SPI data back from the chip and that the SPI settings look right.

Ignoring the program code for the moment, what are the register addresses and what are the 16-bit data values you want to write?

This is great Thank you so much for information, & Thank very much for your understanding

The register addresses & 16-bit data values are

const byte dataA = 100000000001010100000001; const byte dataB = 100000010010101001000010; const byte dataC = 100000100010101000000010; const byte dataD = 100000110000000010000000; const byte dataE = 100001000000010000000000; const byte dataF = 100001011000000000100000;

Hackscribble: Also, can you remove the // from the following statement in the test program, and run it again. No need for screenshot, just want to know what value it prints for SPI Frame ID.

For the SPI Frame Value

SPI Frame ID: 0 Product codes: 4C 63 Product codes:

OK, frame ID of 0 is not a valid value. See section 7.4 of TN0897. There may be a problem in my code. I'll take another look at it.

Can you please answer the question about which device you are actually using. Without the specific datasheet for it, we could be wasting our time here. You are trying to write some specific data into those registers. Presumably, you got the register addresses and data value by looking at a datasheet?

Try this shorter test program for frame ID. Post the serial output and a screenshot, please.

#include <SPI.h>

void showSPIFrameId()
{
  Serial.println("SPI Frame ID:");
  digitalWrite(SS, LOW);
  SPI.transfer(0xFE);
  byte frameID = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  Serial.println(frameID, HEX);
}

void setup (void)
{
  Serial.begin(115200);

  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  SPI.begin ();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  SPI.setDataMode(SPI_MODE0);

  delay(1000);
}

void loop (void)
{
  showSPIFrameId();
  delay(3000);  // 3 seconds delay
}

Hackscribble: Try this shorter test program for frame ID. Post the serial output and a screenshot, please.

yes i try the new code but sill having the same result,

SPI Frame ID: 0

Hackscribble: OK, frame ID of 0 is not a valid value. See section 7.4 of TN0897. There may be a problem in my code. I'll take another look at it.

Can you please answer the question about which device you are actually using. Without the specific datasheet for it, we could be wasting our time here. You are trying to write some specific data into those registers. Presumably, you got the register addresses and data value by looking at a datasheet?

yes this is the dat sheet !! http://www.st.com/content/ccc/resource/technical/document/datasheet/group3/4c/d9/41/be/2e/92/49/0e/DM00062456/files/DM00062456.pdf/jcr:content/translations/en.DM00062456.pdf

That datasheet says the frame ID should be 0x42. Not sure why you are getting 0x00.

Long shot - could you retry the test program but try all the other SPI modes.

Hackscribble:
That datasheet says the frame ID should be 0x42. Not sure why you are getting 0x00.

Long shot - could you retry the test program but try all the other SPI modes.

yes you are right im sorry about the confusing it start from 0X00 in the other datasheet

the pic of Soap is attached with repay

From the datasheet you posted, we have been running the SPI clock too fast. Maximum frequency is 1MHz, but SPI_CLOCK_DIV8 gives a 2MHz clock.

This new version of the test program reduces the speed to 1MHz.

As before, please test what value you get for frame ID in Mode 0, and each of the other modes.

#include <SPI.h>

void showSPIFrameId()
{
  Serial.println("SPI Frame ID:");
  digitalWrite(SS, LOW);
  SPI.transfer(0xFE);
  byte frameID = SPI.transfer(0);
  digitalWrite(SS, HIGH);
  Serial.println(frameID, HEX);
}

void setup (void)
{
  Serial.begin(115200);

  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  SPI.setDataMode(SPI_MODE0);

  delay(1000);
}

void loop (void)
{
  showSPIFrameId();
  delay(3000);  // 3 seconds delay
}

Hackscribble:
From the datasheet you posted, we have been running the SPI clock too fast. Maximum frequency is 1MHz, but SPI_CLOCK_DIV8 gives a 2MHz clock.

This new version of the test program reduces the speed to 1MHz.

As before, please test what value you get for frame ID in Mode 0, and each of the other modes.

I did and still getting the same result each mode,
do you believe that the code is good at the point and it might be the data we sending are not in the order that it should be.

ANY HELP PLEASE