Hi All.
I am in desperate need of help. I'm not sure I've ever done a 32bit driver.
I'm using an ATTiny816 (master) and MCF8316 motor driver (Slave).
Datasheet for the MCF8316 is here: https://www.ti.com/lit/ds/symlink/m...https%3A%2F%2Fwww.ti.com%2Fproduct%2FMCF8316A
Picture below shows a cloud GUI eval software for the MCF8316 which provides the register address and the byte value corrosponding to the settings I put in the GUI.
And then I included my code. And included picture of my serial monitor
My concerns are:
1) I am having trouble reading the registers before and after I write to them. I want to confirm what I wrote.
2) I read, write, and then read again. my serial monitor reflects that. It is one value, then it changes, and then it remains changed.
3) When I power cycle, it goes back to the default value rather than being nonvolatile. Using the eval GUI, I can power cycle and then read registers and they persist from last time. They don't revert to default.
I am in desperate need of help. I'm not sure I've ever done a 32bit driver.
I'm using an ATTiny816 (master) and MCF8316 motor driver (Slave).
Datasheet for the MCF8316 is here: https://www.ti.com/lit/ds/symlink/m...https%3A%2F%2Fwww.ti.com%2Fproduct%2FMCF8316A
Picture below shows a cloud GUI eval software for the MCF8316 which provides the register address and the byte value corrosponding to the settings I put in the GUI.
And then I included my code. And included picture of my serial monitor
My concerns are:
1) I am having trouble reading the registers before and after I write to them. I want to confirm what I wrote.
2) I read, write, and then read again. my serial monitor reflects that. It is one value, then it changes, and then it remains changed.
3) When I power cycle, it goes back to the default value rather than being nonvolatile. Using the eval GUI, I can power cycle and then read registers and they persist from last time. They don't revert to default.
Code:
#include <Wire.h>
#define btn 5 // btn to turn drive on
#define DRV_OFF 1 //Enable Motor Drive
#define MySerial Serial
// Variables
//float battV = 0;
//int battV1 = 0;
//int battV2 = 0;
//int battV3 = 0;
//int battVavg = 0;
int flag1 = 0;
int8_t rxLen = 0;
int8_t len = 0;
void setup() {
Wire.begin();
MySerial.begin(9600);
MySerial.println("MCF8316A Driver and Motor Controller");
analogReference(VDD); //Sets up ADC reference to VDD
// pinMode(batt_fb,INPUT);
// ***Initialize I2C communications:
byte error, address; // variable for scanning all addresses
int nDevices; // number of devices on circuit
MySerial.println("IS323FL3238 Control");
MySerial.println("Scanning for device I2C address...");
nDevices = 0;
for (address = 1; address < 127; address++ ) // I2C Device Address Scanning
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
MySerial.print("I2C device found at address 0x");
if (address < 16)
MySerial.print("0");
MySerial.print(address, HEX);
MySerial.println(" !");
nDevices++;
}
else if (error == 4)
{
MySerial.print("Unknown error at address 0x");
if (address < 16)
MySerial.print("0");
MySerial.println(address, HEX);
}
}
if (nDevices == 0)
MySerial.println("No I2C devices found\n");
else
MySerial.println("done\n");
delay(50);
}
void loop() {
// battV1 = analogRead(batt_fb); //read batt_fb and store in battV
// delay(10);
// battV2 = analogRead(batt_fb);
// delay(10);
// battV3 = analogRead(batt_fb);
// delay(10);
// battVavg = battV1 + battV2 + battV3;
// delay(10);
// battV = 3.3*battVavg/3069;
// MySerial.println("battery voltage (V):");
// MySerial.println(battV);
const uint8_t SLAVE_I2C_ADDRESS = 01;
const uint16_t SLAVE_I2C_REGISTER_ADDRESS = 0x00000080;
Wire.beginTransmission(SLAVE_I2C_ADDRESS);
Wire.write(SLAVE_I2C_REGISTER_ADDRESS);
Wire.endTransmission();
Wire.requestFrom(SLAVE_I2C_ADDRESS, 4); // This register is 32 bits = 4 bytes long
delay(5); // Wait for data to be available
// Read directly into an uint32_t
uint32_t buf;
size_t actually_read = Wire.readBytes((uint8_t*)&buf, 4);
// Print register value
Serial.printf("Register value: %08lx\r\n", __builtin_bswap32(buf));
//const uint16_t SLAVE_I2C_REGISTER_ADDRESS2 = 0x00000082;
//Wire.beginTransmission(SLAVE_I2C_ADDRESS);
//Wire.write(SLAVE_I2C_REGISTER_ADDRESS2);
//Wire.endTransmission();
//Wire.requestFrom(SLAVE_I2C_ADDRESS, 4); // This register is 32 bits = 4 bytes long
//delay(5); // Wait for data to be available
//// Read directly into an uint32_t
//uint32_t buf2;
//size_t actually_read2 = Wire.readBytes((uint8_t*)&buf2, 4);
//// Print register value
//Serial.printf("Register value: %08lx\r\n", __builtin_bswap32(buf2));
delay(200);
if(flag1 == 0){
flag1 = 1;
// MySerial.println("Setting Software Shutdown Mode to Normal Operation");
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000080)); // ISD_CONFIG Address
Wire.write(byte(0x44638C20)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000082)); // REV_DRIVE_CONFIG Address
Wire.write(byte(0x283AF064)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000084)); // MOTOR_STARTUP1 Address
Wire.write(byte(0x4B000B94)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000086)); // MOTOR_STARTUP2 Address
Wire.write(byte(0x2B066000)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000088)); // CLOSED_LOOP1 Address
Wire.write(byte(0x0C3181B0)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x0000008A)); // CLOSED_LOOP2 Address
Wire.write(byte(0x1AAD4312)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x0000008C)); // CLOSED_LOOP3 Address
Wire.write(byte(0x1B800003)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x0000008E)); // CLOSED_LOOP4 Address
Wire.write(byte(0x69BAC4B0)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000090)); // FAULT_CONFIG1 Address
Wire.write(byte(0x47F84886)); // Setting bits
Wire.endTransmission();
delay(50);
Wire.beginTransmission(byte(0x01)); // Targeting MCF8316
Wire.write(byte(0x00000092)); // FAULT_CONFIG2 Address
Wire.write(byte(0x74007800)); // Setting bits
Wire.endTransmission();
delay(50);
}
}