This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi everyone,
thanks to Bruce's help I am progressing in my project, but I still sometime face issues which are a bit weird.
Now, the problem I am having in this moment is that for some reason, my I2C register write function stops working
properly if I call it more than once.
I go in the details: to communicate with the device I am using (an ST25DV), I need to send on I2C the following structure
I2CADDRESS | REG_MSB | REG_LSB | DATA_1 | ... | DATA_n | STOP
Essentially, I need to transmit 2 bytes of register address and 1...n bytes of data to write in the register. So far so good.
To do so, I wrote this function based on the EUSCI_I2C driverlib
int ST25DV_register_write(uint8_t * dataBytes, uint16_t memAddress, uint8_t numberOfBytes, uint8_t device_address) { //Specify slave address EUSCI_B_I2C_setSlaveAddress(EUSCI_B1_BASE, device_address ); //Set in transmit mode EUSCI_B_I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_MODE ); //Enable I2C Module to start operations EUSCI_B_I2C_enable(EUSCI_B1_BASE); __delay_cycles(1000); //Send single byte data. EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, memAddress >> 8); EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, memAddress & 0xFF ); while (!EUSCI_B_I2C_getInterruptStatus (EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0)) /*EMPTY*/; // Wait for shift register to finish uint8_t totalSent = 0; while (totalSent < numberOfBytes - 1) { EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, dataBytes[totalSent] ); totalSent++; } EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, dataBytes[totalSent] ); while (!EUSCI_B_I2C_getInterruptStatus (EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0)) EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B1_BASE); while (!EUSCI_B_I2C_getInterruptStatus (EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0)) EUSCI_B_I2C_disable(EUSCI_B1_BASE); return 0; }
The initial setup of the I2C (speed, pins etc.) is done once at the beginning.
Now, let's say I want to write "0xA0" in register 0x0000. If this is the first call to the write_register function, I obtain the correct trace reported in the screenshot below.
If I want to do the same operation, but AFTER I already called the write_register function to write something else, this is the trace I get
As you can see, the first byte of the address is missing.
In a previous discussion here (MSP430FR2476: Driverlib: Eusci_B I2C multibyte transmission not working - MSP low-power microcontroller...
it was suggested to wait for the transmission to end before sending the next byte, and as you can see in the code this is what I am doing.
I tried different combinations of the driverlib functions (for example using a sendNextByte and then sending a Stop at the end of the transmission),
but I obtain always the same wrong behaviour. I also tried to insert a delay_cycles before staring a new I2C transmission but again, with no luck.
Thanks in advance for the help and have a nice day!
Lorenzo
**Attention** This is a public forum