Hi,
I am currently working on a project and having a hard getting my Arduino Leonardo to read data from AMC 7812 register. Please help
Thank you!
Here is some code I am using:
#include <SPI.h>
const int slaveSelectPin = 10;
void setup() {
Serial.begin(115200);
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}
void loop() {
int result;
// Begin a read or write cycle
digitalWrite(slaveSelectPin, LOW); //Enable the slave
// Send the command to read register 0
SPI.transfer(0x00);
// Now read a byte from the chip. THE VALUE WE SEND MAKES NO DIFFERENCE WHEN READING.
// We just need to generate 8 clock pulses and sample the MISO line to get the data.
// Sending a byte will generate the clock pulses
result = SPI.transfer(0x33);
// Register read operation complete
digitalWrite(slaveSelectPin, HIGH);
Serial.print("Register 0 contains 0x");
Serial.println(result, HEX);
delay(1000);
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.