Part Number:MSP432P401R
Using driverlib, I wrote some code to communicate with a slave sensor. The slave's address is 0xC0 and is interacted with by writing a command byte and initiating a read operation to read the specified register. Here is what I wrote:
#include "driverlib.h"
#define I2C_PINS GPIO_PORT_P3, GPIO_PIN6 + GPIO_PIN7
#define USCI_MODULE EUSCI_B2_BASE
#define SLAVE_ADDRESS 0xC0
/* I2C Master Configuration Parameter */
const eUSCI_I2C_MasterConfig i2cConfig =
{
EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
3000000, // SMCLK = 3MHz
EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 100khz
0, // No byte counter threshold
EUSCI_B_I2C_NO_AUTO_STOP // No Autostop
};
int main(void)
{
WDT_A_holdTimer();
/* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function,
* (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
*/
GPIO_setAsPeripheralModuleFunctionInputPin(I2C_PINS, GPIO_PRIMARY_MODULE_FUNCTION);
/* Initializing I2C Master to SMCLK at 100khz with no autostop */
I2C_initMaster(USCI_MODULE, &i2cConfig);
/* Specify slave address */
I2C_setSlaveAddress(USCI_MODULE, SLAVE_ADDRESS);
/* Set Master in transmit mode */
I2C_setMode(USCI_MODULE, EUSCI_B_I2C_TRANSMIT_MODE);
/* Enable I2C Module to start operations */
I2C_enableModule(USCI_MODULE);
while (I2C_isBusBusy(USCI_MODULE) == EUSCI_B_I2C_BUS_BUSY);
I2C_masterSendSingleByte(USCI_MODULE, 0x08);
I2C_masterReceiveSingle(USCI_MODULE);
}
The result is that a 0x80 is sent and the code hangs indefinitely waiting for an ack but there is no slave with that address so it never comes. I would greatly appreciate it if someone could help me understand why the wrong slave address is being transmitted.
Thanks,
Christian