XMC 2 GO I2C problems send/receive data

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
Hello for my project I choosed the XMC2GO because of its really nice size and features.

I want to control up to three PCA9685 PWM drivers over I2C as well as a MCP23017 I/O expander.
My application is able to send commands over I2C to the PCA9685.
So I can write to the registers but only if I use the debugger by going step by step trough the code.
Otherwise nothing happens. But if I step through the code, after a while of sending data to the registers, the debugger crashes while debugging the function "writeRegisterPCA9685".
The registers of the USIC0_CH1 don't change anymore and the debugger crashes after another few steps.

Do I have to check whether the transmit buffer is free or whats my mistake?

I initialize the I2C on P2.10 and P2.11 with the DAVE APP on 400kBaud.
Also I used the example code of DAVE for the transmission.

// Functions to read and write registers of the PCA9685
bool writeRegisterPCA9685(uint8_t deviceAddress, uint8_t registerAddress, uint8_t registerData){
returnVal = (bool)FALSE;

actualDeviceAddress = (((deviceAddress << 0x01) | 0x80) & PCA9685_WRITE);

// Send START condition as well as slave address and read/write command
deviceSlaveAddress.Data1.TDF_Type = I2C_TDF_MStart;
deviceSlaveAddress.Data1.Data = actualDeviceAddress;
I2C001_WriteData(&I2C001_Handle0, &deviceSlaveAddress);

// Acknowledge & Send control register address
deviceRegisterAddress.Data1.TDF_Type = I2C_TDF_MTxData;
deviceRegisterAddress.Data1.Data = registerAddress;
I2C001_WriteData(&I2C001_Handle0, &deviceRegisterAddress);

// Acknowledge & Send data for registers
deviceRegisterData.Data1.TDF_Type = I2C_TDF_MTxData;
deviceRegisterData.Data1.Data = registerData;
I2C001_WriteData(&I2C001_Handle0, &deviceRegisterData);

// Acknowledge & Send STOP condition
stopCondition.Data1.TDF_Type = I2C_TDF_MStop;
stopCondition.Data1.Data = ubyteFF;
I2C001_WriteData(&I2C001_Handle0, &stopCondition);
return returnVal;
}


Another problem is to receive data.
I don't really know whether the PCA9685 answers, because I don't have an oszilloscope to measure it, but I believe that it does because I can write to it's registers, which change the state of the LEDs.
So I think that it replys if I want to read a register, but the controller doesn't recognized it.
I initialize the Interrupt with the NVIC002, but the interrupt handler function will never be called.

For this code I also used the example of the DAVE App which was designed for the PCA9502 which is very similar to the PCA9685.


uint16_t readRegisterPAC9685(uint8_t deviceAddress, uint8_t registerAddress){

actualDeviceAddress = (((deviceAddress << 0x01) | 0x80) | 0x01); // Combine device address with read flag

// Send START condition as well as slave address and read flag
deviceSlaveAddress.Data1.TDF_Type = I2C_TDF_MStart;
deviceSlaveAddress.Data1.Data = actualDeviceAddress;
while(!(I2C001_WriteData(&I2C001_Handle0, &deviceSlaveAddress)));

// Acknowledge & Send control register address
deviceRegisterAddress.Data1.TDF_Type = I2C_TDF_MTxData;
deviceRegisterAddress.Data1.Data = registerAddress;
while(!(I2C001_WriteData(&I2C001_Handle0, &deviceRegisterAddress)));

// Transmit repeated start condition and slave address
deviceRegisterData.Data1.TDF_Type = I2C_TDF_MRStart;
deviceRegisterData.Data1.Data = actualDeviceAddress;
I2C001_WriteData(&I2C001_Handle0, &deviceRegisterData);

// Read Data from slave
deviceReadData.Data1.TDF_Type = I2C_TDF_MRxAck1;
deviceReadData.Data1.Data = ubyteFF;
I2C001_WriteData(&I2C001_Handle0, & deviceReadData);

// Send STOP condition
stopCondition.Data1.TDF_Type = I2C_TDF_MStop;
stopCondition.Data1.Data = ubyteFF;
I2C001_WriteData(&I2C001_Handle0, &stopCondition);

return actualDataReceived;
}

void FIFO_Receive_Int_Handler(void){
actualDataReceived = 0x0000;
successfullDataReceived = (bool)FALSE;
// Read receive FIFO buffer and put the data to "actualDataReceived"
I2C001_ReadData(&I2C001_Handle0, &actualDataReceived);
// If the FIFO buffer is 0xFFFF there were no valid data received
if(actualDataReceived != 0xFFFF){
successfullDataReceived = (bool)TRUE;
}
}


Can anybody help me with my problem?

Greetings from Germany
Christian

Code of my project:
0 Likes
1 Reply
Not applicable
Hi Christian,

From your code, it doesn't seems to have any problems.
Do you mind if you could post your whole project here so that we could download the project to our board and test it out?
0 Likes