Hi guys,
i wasn't sure if this belongs to the LPCOpen or the LPC15xx forum.
I got the following problem:
I am using the example code or the I2C master interrupt mode of LPCopen on the OM13056 Evalboard (LPC1549 processor). The configuration of the I2C stays the same like the example (Clk_Div = 40 -> 72MHz/40 = 1.8MHz,Bus Speed = 100kHz). In the operation i just want to read 2 Bytes of data (no writing).
The init function:
void Init_I2C_Drucksensor(void) { I2C_Xfer.slaveAddr = AG4_Sens_ADR; //Adr. des sensor I2C_Xfer.status = 0; //Status auf 0 I2C_Xfer.txSz = 0; //es wird nichts geschrieben I2C_Xfer.txBuff = NULL; //Buffer fürs schreiben auf null zeigen Chip_IOCON_PinMuxSet(LPC_IOCON, PORT_0, PIN_22, (IOCON_DIGMODE_EN | I2C_Mode)); Chip_IOCON_PinMuxSet(LPC_IOCON, PORT_0, PIN_23, (IOCON_DIGMODE_EN | I2C_Mode)); Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SCL); Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SDA); Chip_I2C_Init(LPC_I2C0); Chip_I2C_SetClockDiv(LPC_I2C0, I2C_CLK_Div); //Chip_I2CM_SetBusSpeed(LPC_I2C0, I2C_400kHz_Speed); Chip_I2CM_SetBusSpeed(LPC_I2C0, I2C_100kHz_Speed); Chip_I2CM_Enable(LPC_I2C0); NVIC_EnableIRQ(I2C0_IRQn); NVIC_ClearPendingIRQ(I2C0_IRQn); }
The function to read out the data:
uint16_t ReadPres(void) { uint8_t RohDaten[Pressure_Data_Size], StatusVal; uint16_t Pressure = 0, Buffer = 0;; //Auslesen des Sensors via I2C I2C_Xfer.rxSz = Pressure_Data_Size; //Menge an empfangenen Bytes I2C_Xfer.rxBuff = RohDaten; //Buffer zum empfangen #ifndef I2C_Polling_Mode Chip_I2CM_Xfer(LPC_I2C0, &I2C_Xfer); Chip_I2C_EnableInt(LPC_I2C0, (I2C_INTENSET_MSTPENDING | I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR)); while (I2C_Xfer.status == I2CM_STATUS_BUSY) {__WFI();} Chip_I2C_ClearInt(LPC_I2C0, (I2C_INTENSET_MSTPENDING | I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR)); #else Chip_I2CM_XferBlocking(LPC_I2C0, &I2C_Xfer); //ReadI2C(AG4_Sens_ADR, RohDaten, Pressure_Data_Size); #endif //Verarbeiten der Daten StatusVal = (RohDaten[0]>>6) & 0x03; if(StatusVal == 0) { Buffer = ((RohDaten[0]<<8) | (RohDaten[1])) & 0x3FFF; Pressure = Buffer*3 + (Buffer/10)*3 + (Buffer/100)*9 + (Buffer/1000)*1; }else{ Buffer = ((RohDaten[0]<<8) | (RohDaten[1])) & 0xC000; //Rückgabe der Fehlermeldung Pressure = Buffer; } return Pressure; }
The sampling rate is controlled by the RIT (Interrupt every 1ms -> all 10ms getting a new sample).
I tried the code in interrupt mode (default) and in polling mode.
In interrupt mode i stuck at the line in the reading function:
while (I2C_Xfer.status == I2CM_STATUS_BUSY) {__WFI();}
At the polling mode at the line where the status gets requested.
If i meassure on the Pins there is no activity. So i think the data is never written and that's the reason why the status never changes to OK or something else.
But i don't have any idea why this is so, so i appreciate all kind of help/information.
Best regards
Patrick
Hi guys,
i found the error. It was necessary to call the function Chip_SWM_Init();
Oh i forgot the interrupt service routine:
void I2C0_IRQHandler(void)
{
Chip_I2CM_XferHandler(LPC_I2C0, &I2C_Xfer);
}