I'm trying to control AD7091-8 using Arduino Due.
This IC calls for 16 bit SPI R/W. I'd read that I can change the transmit and receive bits of Arduino DUE by changing a register (bits 4-7 of SPI_CSR).
I was able to change the SPI of Due from 8 to 16 bits. Confirmed this by looking at SCLK and MOSI in the scope. However, the data I want to transfer is becoming intermittent.
I want to send 0x1000. On 8 bits, using the line
SPI.transfer(10,0x10,SPI_LAST);
I really can see this being sent on MOSI.
However, when I'm on 16 bits, the line
SPI.transfer(10,0x1000,SPI_LAST);
It's either becoming 0x0000 or 0x0008. I'm losing the bit or it's becoming LSB_FIRST. Not MSB_FIRST.
Below is the actual code.
#include <SPI.h>
#include "C:\Users\Smart Surface 2\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system\CMSIS\Device\ATMEL\sam3xa\include\component\component_spi.h"
#include "C:\Users\Smart Surface 2\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system\CMSIS\Device\ATMEL\sam3xa\include\instance\instance_spi0.h"
#define CS 10
void setup() {
pinMode(CONV,OUTPUT);
Serial.begin(9600);
SPI.begin(CS);
SPI.setDataMode(CS, SPI_MODE0);
SPI.setClockDivider(CS,21);
REG_SPI0_WPMR=0x53504900;
REG_SPI0_CR=0x1;
SPI0->SPI_CSR[0]=0x00001580;
SPI.setBitOrder(MSBFIRST);
delay(1);
}
void loop() {
SPI.transfer(CS,0x1000,SPI_LAST);
int a = SPI.transfer(CS,0x0000, SPI_LAST);
delay(1000);
Serial.println(a);
}
How can I make my data reliable and the order still with MSB first?