I2C driver for MCF8316 32bit?

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.
#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);
  }
}

I can't really look at your code now and no experience with your components but below stood out.

Does that address fit in 16 bits?

As far as I know, that writes a single byte.

I got the Wire.write(SLAVE_I2C_REGISTER_ADDRESS); from the arduino example MASTER READ code.

I tried both 0x00000080 and 0x80 and I got the same results.

This is a reserved I2C address. No slave should have such an address.

A delay of 100µs is required between bytes written.

All that and whatever else may come up indicates that a special SoftwareI2C driver is required for this chip.

I'd look for a more conforming chip for your project.

Hi Thanks for commenting.
I got 01 from both the datasheet and:

image

What do you mean a special software I2C driver?

A driver that does bit banging for the communication with that device. The standard (hardware based) drivers don't handle such an non-conforming slave.

The 177 pages are too many to read for me.
The I2C address of 0x01 is weird and not according to the I2C standard, but the Wire library should work with it.

It can write its data to EEPROM, but you probably have to give the command for that.

If it would have a 8-bit register address and 32-bit registers, then this

    Wire.beginTransmission(byte(0x01));   // Targeting MCF8316
    Wire.write(byte(0x00000080));         // ISD_CONFIG Address
    Wire.write(byte(0x44638C20));         // Setting bits
    Wire.endTransmission();

should be this:

    Wire.beginTransmission(0x01);         // I2C address of MCF8316
    Wire.write(0x80);                     // ISD_CONFIG register address
    Wire.write(0x44);                     // highest byte of the 32 bits
    Wire.write(0x63);                     // second byte of the 32 bits
    Wire.write(0x8C);                     // third byte of the 32 bits
    Wire.write(0x20);                     // lowest byte of the 32 bits
    Wire.endTransmission();

However, it has a 24-bit control word, a datalen, a CRC. Some registers can be read, others be written. It is not easy. Try to find a library for it.

Hello @Frozenguy !
Did you found a correct library to communicate between ATmega and the MCF8316 through I2C?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.