Go Down

Topic: SPI on Arduino Due (Read 338 times) previous topic - next topic

waalsh

Hello, small question. Referring to SPI pins on Uno or Mega is easy (Mega mosi=51, miso=50). But how do you name the Mosi and Miso for the Due?

Thanks,
Hugo

MorganS

Use the SPI connector in the middle of the board. See the diagram in the first post at the top of this forum.

MOSI/MISO isn't copied on any other pin on the Due.
GoForSmoke: "What GShield? You never mentioned a shield."

bobomomo

I have an ADXL345 accelerometer evaluation board. I am able to interface with it very well with my Arduino Uno. I can write registers to it as well as read data from the device registers without any issues.

I started using Arduino Due yesterday, and I seem to not understand how to put values into the register. The page on the website is very confusing to me "http://arduino.cc/en/Reference/DueExtendedSPI"

Could someone please give me an example of how to input a value on to the register?

MarkT

#3
Mar 10, 2015, 07:22 pm Last Edit: Mar 10, 2015, 07:26 pm by MarkT
You don't name them, the SPI hardware is completely different, just look at the Due SPI examples.

[ actually there don't appear to be any! - look at the docs http://arduino.cc/en/Reference/DueExtendedSPI ]
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

bobomomo

I am setting up my DUE with the following code:

void setup()
{
  SPI.begin(4);
  SPI.setClockDivider(4,21);
  SPI.setDataMode(4,SPI_MODE3);
  SPI.setBitOrder(4,MSBFIRST);
  Serial.begin(9600);
 

// Want to put in inside $0x2D the value 0x08
  SPI.transfer(4, 0x2D, SPI_CONTINUE);
  SPI.transfer(4, 0x08, SPI_CONTINUE);

// Want to put in inside $0x31 the value 0x03
  SPI.transfer(4, 0x31, SPI_CONTINUE);
  SPI.transfer(4, 0x03, SPI_CONTINUE);
}

// AM I DOING THIS RIGHT?

void loop()
{
 // I want to read from 16-bit data from $0x36 & $0x37
 byte response = SPI.transfer(4, 0xB6, SPI_CONTINUE);
 byte response1 = SPI.transfer(4, 0x00);
 }

// AM I DOING THIS RIGHT?

MarkT

You probably don't want the continue on the second transfer of each register write.  This
controls the chip select action (stay low or revert to high).  Normally each register
access would be a single SPI transaction (but check the datasheet, devices differ - this
should also tell you which mode to use (normally mode0 is right).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

bobomomo

Thanks MarkT.

I modified:

// Want to put in inside $0x2D the value 0x08
  SPI.transfer(4, 0x2D, SPI_CONTINUE);
  SPI.transfer(4, 0x08, SPI_CONTINUE);

to

// Want to put in inside $0x2D the value 0x08
  SPI.transfer(4, 0x2D, SPI_CONTINUE);
  SPI.transfer(4, 0x08);

and it works.

MarkT

Great!  Did you check the mode was right (using the wrong mode can seem to work
but be either unreliable or shift your data one bit position).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up