I have 3 weeks now failing to just get the WhoAmI value from the I2C module "FXOS8700 + FXAS21002"
What is wrong with my code, what am I missing?
The supply voltage to the I2C module is 5V. Before programming the mcu, Both the SCL and SDA lines measure 5 volts with reference to the ground. Then when I'm in debugg, with oscilloscope connected to the I2C bus, The voltage drops from 5V to 3.75V and stay there when I mux PortD in my code. Shouldn't i be seeing square waves on the scl line even with no data transfer between mcu and the module?
I get Arbitration lost in the status register.
What is wrong with my code?
Below is my code
Printing "ReceivedByte" array on tera term shows wrong WhoAmI value
uint8_t Receivedbyte[3];
uint8_t WhoAmI_address[1] = {0x0D};
size_t RegSize = 1;
void Mcu_Initialise()
{
PORTD->PCR[8] = 0x01000000; //clear the ISF flag
PORTD->PCR[9] = 0x01000000; //clear the ISF flag
PORTD->PCR[8] |= 0x00000200; //mux PTD8 for I2C0_SCL
PORTD->PCR[9] |= 0x00000200; //mux PTD9 for I2C0_SDA
SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK; // I2C0 clock
SIM->SCGC5 |= 0x00002000U; //portD
//I'm not sure about the following two lines
EnableIRQ(I2C0_IRQn);
NVIC_SetPriority(I2C0_IRQn,0);
}
void I2C_Initialise()
{
I2C0->A1 = 0;
I2C0->F = 0;
I2C0->C1 = 0;
I2C0->S = 0xFFU;
I2C0->C2 = 0;
I2C0->S |= I2C_S_IICIF_MASK ; //clear IICIF
I2C0->F = 0x27U; //bus clock is 48MHz, calculated baud rate for 100khz
I2C0->C1 = I2C_C1_IICEN_MASK;
//I2C0->C1 |= I2C_C1_IICIE_MASK; // When I enable this interrupt the system gets stuck in CLOCK_GetOutClkFreq() function. When I disable it I'm able to run my code from mcu_initialise() to Read()
void StartCondition()
{
I2C_MasterStart(I2C0, FXOS8700CQ_Address, kI2C_Write);
}
void StartRepeat()
{
I2C_MasterRepeatedStart(I2C0, FXOS8700CQ_Address, kI2C_Read);
}
void sendRegister()
{
I2C_MasterWriteBlocking(I2C0, WhoAmI_address, RegSize, kI2C_TransferNoStopFlag);
}
void Read()
{
I2C_MasterReadBlocking(I2C0,ReceivedByte, RegSize, kI2C_TransferNoStartFlag);
}
int main()
{
BOARD_InitPins();
__disable_irq();
InitVersion();
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
mcu_Initialise();
intitialiseI2C();
StartCondition();
sendRegister();
StartRepeat();
Read();
}