I2C master trouble

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.
Anonymous
Not applicable

Hello,

I started exploring the world of PSoC with PSOC 4 BLE kit and it was great until I ran into trouble making i2c bus work.

I am trying to hook up i2c character LCD, however it seems like I am unable to initialize i2c properly. 

I tried different pins/speeds, using low level i2c api and high level - nothing helps.

I check the SCL pin with oscilloscope and don't see any signal. 

I tried example projects - still no signal on SCL and SDA.. 

I attach my code and project:

   

<pre><code>
#include <project.h>
#include "LiquidCrystal_I2C.h"

   

__IO uint32_t TimingDelay = 0;
uint32_t DeviceAddr = 78;
uint16 shit=0;
int i=0;
 int main(void)
{  
  CyGlobalIntEnable;
  
    
  PWM_1_Start();   
  
  I2C_M_Start();

   


    PWM_1_WriteCompare(0);

   


    while(1){ 
      
        I2C_M_I2CMasterWriteBuf(DeviceAddr, (uint8 *)DeviceAddr, 1, 0);
        I2C_M_write_byte(DeviceAddr,67);
        I2C_M_I2CMasterSendStart(DeviceAddr,0);
          CyDelay(1000);
        }
  
}  
</code>

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You find documentation and schematics for all the kits you successfully installed under Programs(x86)\Cypress\,,,\Hardware

   

The port5 pins fur I2C are on header J10 pins 12 and 14

   

 

   

Bob

View solution in original post

0 Likes
8 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Sarunas.

   

I would suggest you to use P5_0 and P5_1 for I2C, the required pullup resistors are already provided on the board and the FRam is on the same bus

   

Your first access to the I2C interface must fail:

   

I2C_M_I2CMasterWriteBuf(DeviceAddr, (uint8 *)DeviceAddr, 1, 0);

   

When the device address of the I2C-LCD really is 0x78 you are trying to submit a databyte from the address of 0x78 which is from flash, Probably not what you want.

   

You did not provide a link to the LCD's datasheet, so I cannot check what you have to send.

   

The following WriteByte() function will fail because you did not issue a Start() condition.

   

The next SendStart() is not followed by a SendStop()

   

All I2C-APIs return a status indicating success or failure. Best is to check that.

   

For both the APIs SendStart() and WriteBuf() the last parameter has a meaningful #define (to be found in the .h-file), better to use that, makes it clear what you want to do.

   

 

   

Bob

0 Likes
Anonymous
Not applicable
        thank you for your suggestions. I probably did not make myself clear. shouldnt there be a signal in SCL even though the data is not being transmitted? I am not initializing lcd yet, just checking if I get a signal on I2c and any combination seems not to be working...   
0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Sarunas: Well I have look over your program and I think there is a few issue with it. The I2C pins are P3-4 and P3-5 these are set for the Arduino I2C output pins on the Pioneer board J3. Also you need to have pullup resistors on these pins.  Also I have no ideal what I2C LCD display you are using. So I can't check your address and commands. Also if you look at the PSOC Ble  example program they have both an I2C device and also an I2C LCD device in their program.  There is also a I2C test program in the examples that should help also.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You will not see a signal without pullups.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks! I will try your suggestions 🙂 i think i tried all allowed ports already, but will do it again.

UPDATE: I managed to see the signal. The problem was indeed passing an argument to I2C_MASTERWRITEBUFFER. I tried sending the pointer of the variable, while it wants an array 🙂

P.S. Are there pins on the pioneer baseboard to which pins 5.0 and 5.1 are connected? Can't find anything in documentation.. also doesn't seem to be on the board.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You find documentation and schematics for all the kits you successfully installed under Programs(x86)\Cypress\,,,\Hardware

   

The port5 pins fur I2C are on header J10 pins 12 and 14

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I got it working on other pins. Thanks for your help. It turns out, that address had to be shifted by one bit (compared to stm32 i2c configuration). 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Fine!

   

Happy coding

   

Bob

0 Likes