Not applicable
Sep 22, 2017
02:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 22, 2017
02:40 AM
Hello everyone,
I'm trying to use the example on i2c_master.h from line 805 to 827 to use I2C bus in the Xmc4700 Relax kit, I chose pin P0.13 and P3.15 on the DAVE CE (Manual Pins Allocator) and in Advanced Settings the Transmit and Receive mode are by Interrupt.
The only thing that are changed in this code are:
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,mem_address,1,false);
and that I put the code in a While loop:
while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
I;m checking if for signal with a scope and so far there is no signal with pull up resistor or with out pull up resistors.
Thanks in advance for the help
Best regards
I'm trying to use the example on i2c_master.h from line 805 to 827 to use I2C bus in the Xmc4700 Relax kit, I chose pin P0.13 and P3.15 on the DAVE CE (Manual Pins Allocator) and in Advanced Settings the Transmit and Receive mode are by Interrupt.
The only thing that are changed in this code are:
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,mem_address,1,false);
and that I put the code in a While loop:
while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
I;m checking if for signal with a scope and so far there is no signal with pull up resistor or with out pull up resistors.
Thanks in advance for the help
Best regards
13 Replies
Sep 22, 2017
03:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 22, 2017
03:55 AM
Are you using DAVE 4? I'm also having difficulty using I2C protocol on DAVE4.
I discovered that if you force an init before transmitting and receiving it "works".
Try this:
while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,true,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
Please, give me a feedback.
PS: are you trying to read or you just want to send some data to a device?
I think if the IRQ is enabled on dave app you could use the function I2C_MASTER_Transmit() instead of I2C_MASTER_TransmitIRQ(). Like this:
while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
I2C_MASTER_StartTransmit(&I2C_MASTER_EEPROM,true,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_StartTransmit(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
I discovered that if you force an init before transmitting and receiving it "works".
Try this:
while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,true,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_StartTransmitIRQ(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
Please, give me a feedback.
PS: are you trying to read or you just want to send some data to a device?
I think if the IRQ is enabled on dave app you could use the function I2C_MASTER_Transmit() instead of I2C_MASTER_TransmitIRQ(). Like this:
while(1)
{
mem_address[0] = 0x00;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_EEPROM);
I2C_MASTER_StartTransmit(&I2C_MASTER_EEPROM,true,SLAVE_ADDRESS,mem_address,1,false);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
I2C_MASTER_StartTransmit(&I2C_MASTER_EEPROM,false,SLAVE_ADDRESS,tx_buffer,64,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));
}
Not applicable
Sep 22, 2017
05:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 22, 2017
05:45 AM
I tried this solution, but it always get stuck in while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));. The idea right now is just send a message but the transmit mode and receive mode handling must be an Interrupt
Sep 22, 2017
01:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 22, 2017
01:48 PM
Hello people.
I'm also having the same problem, I'm using the XMC1402 T-038, the I2C only transmits, after an I2C_MASTER_Init ().
I2C_MASTER_Init (& I2C_MASTER_0);
I2C_MASTER_Transmit (& I2C_MASTER_0,1, SLAVE_ADDRESS, 0xf, 1,0);
And there is another problem the Call Back from tx and RX is not working.
I want to use an external EEprom but this is so difficult.
I'm also having the same problem, I'm using the XMC1402 T-038, the I2C only transmits, after an I2C_MASTER_Init ().
I2C_MASTER_Init (& I2C_MASTER_0);
I2C_MASTER_Transmit (& I2C_MASTER_0,1, SLAVE_ADDRESS, 0xf, 1,0);
And there is another problem the Call Back from tx and RX is not working.
I want to use an external EEprom but this is so difficult.
Attachments are accessible only for community members.
Sep 25, 2017
12:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
12:33 AM
alanblu wrote:
I tried this solution, but it always get stuck in while(I2C_MASTER_IsTxBusy(&I2C_MASTER_EEPROM));. The idea right now is just send a message but the transmit mode and receive mode handling must be an Interrupt
Are you using DAVE4? It seems that I2C is problematic on it.
Attached you can check my code that I've been using to transmit and receive data from a slave. Its kind of "working" reggarding the bug mentioned about the I2C Init.
The interrupts are configured like that:
Sep 25, 2017
12:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
12:36 AM
Rodrigo wrote:
Hello people.
I'm also having the same problem, I'm using the XMC1402 T-038, the I2C only transmits, after an I2C_MASTER_Init ().
I2C_MASTER_Init (& I2C_MASTER_0);
I2C_MASTER_Transmit (& I2C_MASTER_0,1, SLAVE_ADDRESS, 0xf, 1,0);
And there is another problem the Call Back from tx and RX is not working.
I want to use an external EEprom but this is so difficult.
DAVE4? I used to have this problem also. The call back wasn't working.
I deleted the project, created again and it worked. I also changed the Manual Resource Assignment to this:
Not applicable
Sep 25, 2017
04:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
04:12 AM
persike wrote:
Are you using DAVE4? It seems that I2C is problematic on it.
Attached you can check my code that I've been using to transmit and receive data from a slave. Its kind of "working" reggarding the bug mentioned about the I2C Init.
The interrupts are configured like that:
Thank you persike,
I tried this but I'm still getting stuck in the while:
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
If i erase line 89 and 94 the software runs one time and them it get stuck in line 84, if I let line 89 or 94, the software get stuck in the first while that it founds.
I changed the interrupt as you show me in the pictura
Ahh and I'm using DAvE 4.3.2
Regards
Sep 25, 2017
05:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
05:47 AM
alanblu wrote:
Thank you persike,
I tried this but I'm still getting stuck in the while:
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
If i erase line 89 and 94 the software runs one time and them it get stuck in line 84, if I let line 89 or 94, the software get stuck in the first while that it founds.
I changed the interrupt as you show me in the pictura
Ahh and I'm using DAvE 4.3.2
Regards
I forgot to mention that I'm debugging with breakpoints between them. If I just let it run it stucks on that while also.
Add some delay between the I2C_Transmit() and I2C_Receive() or use breakpoints like me (it must be a big delay).
Like this:
// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
DELAY;
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
DELAY;
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
It should work.
Not applicable
Sep 25, 2017
06:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
06:22 AM
I'm still getting stuck in the same place
#define DELAY (500000)
// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
#define DELAY (500000)
// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
Sep 25, 2017
06:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
06:36 AM
alanblu wrote:
I'm still getting stuck in the same place
#define DELAY (500000)
// Sending a data to X_LEVEL_UPPER register
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
i2c_data = 0x50; // any value, just to test if the I2C is working as expected
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time <- this one doesn't need because it's not a new transmission.
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,false,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
That code send 0x50 to the register X_LEVEL_UPPER of slave address SENSOR_WRITE_ADDRESS. So it's not necessary to add the second I2C_MASTER_INIT() because it is the same transmission. That's why the stop bit parameter is false in the same Transmission and True at the second one.
If you just wanna to transmit one byte you can try this:
i2c_data = X_LEVEL_UPPER;
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work atleast one time
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SENSOR_WRITE_ADDRESS,&i2c_data,1,true);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
// Reading
I2C_MASTER_Init(&I2C_MASTER_0); // if you don't force an init everytime before a communication the protocol doesn't work
delay(DELAY);
I2C_MASTER_Receive(&I2C_MASTER_0,true,SENSOR_READ_ADDRESS,&vector[0],6,true,false);
while(!globalFlags.txComplete & !globalFlags.rxComplete & !globalFlags.nackReceived & !globalFlags.arbitrationLost & !globalFlags.errorDetected);
clearGlobalFlags();
Not applicable
Sep 25, 2017
07:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
07:14 AM
I went back to the following configuration:
mem_address[0] = IO_STATE;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,mem_address,1,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,tx_buffer,5,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));
and I tried all the possible configuration of true and false on the I2C_MASTER_Transmit function I noticed that the while get stuck when I have a true statement in the second argument of any of the call of the transmit function,but when I transmit without the true statement I only get a bit change in BOTH channels (SDA and SCL) does this mean something?
mem_address[0] = IO_STATE;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,mem_address,1,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,tx_buffer,5,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));
and I tried all the possible configuration of true and false on the I2C_MASTER_Transmit function I noticed that the while get stuck when I have a true statement in the second argument of any of the call of the transmit function,but when I transmit without the true statement I only get a bit change in BOTH channels (SDA and SCL) does this mean something?
Sep 25, 2017
11:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 25, 2017
11:48 PM
alanblu wrote:
I went back to the following configuration:
mem_address[0] = IO_STATE;//memory which need to be read from slave
//Write data to IO EXPANDER
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,mem_address,1,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));
I2C_MASTER_Init(&I2C_MASTER_0);
delay(DELAY);
I2C_MASTER_Transmit(&I2C_MASTER_0,true,SLAVE_ADDRESS,tx_buffer,5,true);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_0));
and I tried all the possible configuration of true and false on the I2C_MASTER_Transmit function I noticed that the while get stuck when I have a true statement in the second argument of any of the call of the transmit function,but when I transmit without the true statement I only get a bit change in BOTH channels (SDA and SCL) does this mean something?
Without the true the comunication shouldn't work, because the uc will not send start and stop bit conditions.
I2C_MASTER_STATUS_t I2C_MASTER_Transmit(I2C_MASTER_t *handle, bool send_start, const uint32_t address, uint8_t *data, const uint32_t size, bool send_stop)
Apparently you have a different problem than my one, sorry for not solving it.
Good luck! Hope someone that uses the same kit that you have been using helps you.
Not applicable
Sep 28, 2017
12:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 28, 2017
12:22 AM
persike wrote:
Without the true the comunication shouldn't work, because the uc will not send start and stop bit conditions.
I2C_MASTER_STATUS_t I2C_MASTER_Transmit(I2C_MASTER_t *handle, bool send_start, const uint32_t address, uint8_t *data, const uint32_t size, bool send_stop)
Apparently you have a different problem than my one, sorry for not solving it.
Good luck! Hope someone that uses the same kit that you have been using helps you.
Ok, Thanks for the Help!
Not applicable
Oct 08, 2017
11:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 08, 2017
11:27 PM
Hi everyone!
The problem I had was due to the wrong address. I could solve it thanks to the support team.
"Address(address) should reserve an additional bit at the LSB for read/write indication. For example, address 0x05 should be provided as 0x0a"
Best regards
Alan
The problem I had was due to the wrong address. I could solve it thanks to the support team.
"Address(address) should reserve an additional bit at the LSB for read/write indication. For example, address 0x05 should be provided as 0x0a"
Best regards
Alan