1 2 3 Previous Next 36 Replies Latest reply on May 14, 2015 4:03 AM by user_444739275

    I2C  programming ?

    user_444739275

      Hello ,

      I need help to understand I2C programming for psoc 4. I don't have enough knowledge about I2C communication. I looked some project sample But Its not clear for me

         

      how to write basic sample code for  I2C communication. ?

         

      1.start I2C

         

      2.               Writes data over I2C

         

      3.stop I2C

         

      4. start I2C

         

      5.               Reads data from I2C

        • 1. Re: I2C  programming ?
          user_1377889

          You will need a second device that will function as I2C slave. Have you got one? So first you will have to decide who is I2C-master and who is I2C-slave.

             

          Only the master can read and write to/from the slave. There are master/slave examples which you should understand first.

             

          Electrically, the two I2C-lines clock and data need pullup resistors for the interface to function properly.

             

           

             

          Bob

          • 2. Re: I2C  programming ?
            user_14586677

            Although this video is for PSOC 1 the basic principles the same -

               

             

               

                

               

                      https://www.youtube.com/watch?v=CCwiJcVDl8c

               

             

               

            Also search youtube for I2C, there are other videos there as well.

               

             

               

            In Creator there are examples, on Creator start page link "Find Example projects"

               

             

               

            Regards, Dana.

            • 3. Re: I2C  programming ?
              user_444739275

              Hello

                 

              actully I want to display  data to LCD via i2c communication. 

                 

              I need to develope algorithms.  what I have to Do ?

                 

              1.  start  I2C

                 

              2.  LCD_Start()   

                 

              2.   send data to LCD

                 

              3. LCD_DisplayOn()

                 

              4. LCD _PrintString()

                 

              5. LCD_Stop()

                 

              6.  Stop I2c 

                 

              I am trying to make program on psoc creator 3.0.  In my next post I will try to write compelete program

              • 4. Re: I2C  programming ?
                user_1377889

                No need to stop the I2C, let it run as long as there is power applied.

                   

                Give us a link to the LCD datasheet with I2C interface that you want to connect to your PSoC board.

                   

                Which board are you using? Give us Cypress part no. or link.

                   

                 

                   

                Bob

                • 5. Re: I2C  programming ?
                  user_14586677

                  The basic protocol is a start/stop -

                     

                   

                     

                  Protocol

                     

                  Communication via I2C is more complex than with a UART or SPI solution. The signalling must adhere to a certain protocol for the devices on the bus to recognize it as valid I2C communications. Fortunately, most devices take care of all the fiddly details for you, allowing you to concentrate on the data you wish to exchange.

                     

                  Basics

                     

                  Standard 7-bit address transfer message.

                     

                  Messages are broken up into two types of frame: an address frame, where the master indicates the slave to which the message is being sent, and one or more data frames, which are 8-bit data messages passed from master to slave or vice versa. Data is placed on the SDA line after SCL goes low, and is sampled after the SCL line goes high. The time between clock edge and data read/write is defined by the devices on the bus and will vary from chip to chip.

                     

                  Start Condition

                     

                  To initiate the address frame, the master device leaves SCL high and pulls SDA low. This puts all slave devices on notice that a transmission is about to start. If two master devices wish to take ownership of the bus at one time, whichever device pulls SDA low first wins the race and gains control of the bus. It is possible to issue repeated starts, initiating a new communication sequence without relinquishing control of the bus to other masters; we’ll talk about that later.

                     

                  Address Frame

                     

                  The address frame is always first in any new communication sequence. For a 7-bit address, the address is clocked out most significant bit (MSB) first, followed by a R/W bit indicating whether this is a read (1) or write (0) operation.

                     

                  The 9th bit of the frame is the NACK/ACK bit. This is the case for all frames (data or address). Once the first 8 bits of the frame are sent, the receiving device is given control over SDA. If the receiving device does not pull the SDA line low before the 9th clock pulse, it can be inferred that the receiving device either did not receive the data or did not know how to parse the message. In that case, the exchange halts, and it’s up to the master of the system to decide how to proceed.

                     

                  Data Frames

                     

                  After the address frame has been sent, data can begin being transmitted. The master will simply continue generating clock pulses at a regular interval, and the data will be placed on SDA by either the master or the slave, depending on whether the R/W bit indicated a read or write operation. The number of data frames is arbitrary, and most slave devices will auto-increment the internal register, meaning that subsequent reads or writes will come from the next register in line.

                     

                  Stop condition

                     

                  Once all the data frames have been sent, the master will generate a stop condition. Stop conditions are defined by a 0->1 (low to high) transition on SDA after a 0->1 transition on SCL, with SCL remaining high. During normal data writing operation, the value on SDA should not change when SCL is high, to avoid false stop conditions.

                     

                   

                     

                  Regards, Dana.

                  • 6. Re: I2C  programming ?
                    user_14586677

                    If your LCD is 44780 compatible controller just use Character LCD. It connects

                       

                    via 4 pins for data, 3 pins for control.

                       

                     

                       

                    If the LCD has a I2C interface, then select Character LCD with I2C interface and

                       

                    place an I2C master component.

                       

                     

                       

                    Regards, Dana.

                    • 7. Re: I2C  programming ?
                      user_444739275

                      Hello

                         

                      I am using Jhd 16 2A LCD. I am attaching project without Program

                      • 8. Re: I2C  programming ?
                        user_1377889

                        Your selected LCD Jhd 16 2A uses an 8-bit wide databus and some control-signals. There is no component to directly connect the LCD to your PSoC, so you will have to program everything yourself which is not an easy job.

                           

                        What is your I2C interface for? Do you want to build an LCD-module with an I2C interface? What will be the Master??

                           

                         

                           

                        Bob

                        • 9. Re: I2C  programming ?
                          user_14586677

                          Your Jhd 16 2A has a 44780 compatible controller in it, so

                             

                          use Character LCD for the module. It does not have an I2C

                             

                          interface. It takes 4 bits + 3 control lines to connect to PSOC.

                             

                          In its component datasheet are the instructions (APIs) to

                             

                          control it.

                             

                           

                             

                          The above componnet uses one contiguous port to connect. If you

                             

                          need to spread across multiple ports the connections see Kees

                             

                          component. www.cypress.com/

                             

                           

                             

                          Regards, Dana.

                          • 10. Re: I2C  programming ?
                            user_242978793

                            Vead:  I sent you a working program that writes to a character LCD a few days ago.  LCD_Arduino.bundel01. this program is working and does not need an I2C interface.  Why have you not used this program and converted it to the Cy8CKIT-049-4200 that you have?  When I researched the data sheet for your display I am not sure that it will work with a 44780 type display but you should try it anyway. It it works fine if it fails then get a 44780 compatable display and you will be in business with a working display!!

                               

                            Bobgoar

                            • 11. Re: I2C  programming ?
                              user_444739275

                              Hello

                                 

                               I Have done Projects based on LCD.  LCD Display is not Problem. I want to use I2C communication. that's why I am trying to interface LCD with I2C 

                                 

                              Look at following project sample. I did small change.   I placed I2C component. 

                                 

                              1. start I2C

                                 

                              2 stop I2C

                                 

                              3. send

                                 

                              4 receive

                                 

                              how to send data on LCD  via I2C communication ?

                              • 12. Re: I2C  programming ?
                                user_242978793

                                Get an example I2C program from the example programs in Psoc 4 M page and then transfer the I2C data from the example to your program.  You can not use the current display on I2C just the data you receive from the I2C device.  here is the address http://www.cypress.com/?rID=108008. or this is a good manual for all Psoc types and how to use I2C http://www.cypress.com/?docID=52704. There is a good example in 100 projects in 100 days http://www.element14.com/community/thread/25071/l/psoc-4-pioneer-kit-community-project035-uart-i2c-and-spi-joystick-example But you need a RTC chip to make this app work.  If you want to use the I2C to talk to an LCD you need to replace your LCD with another one or use one of these

                                   

                                i2c / SPI character LCD backpack you feed in I2C signal on 2 wires  and it provides the drive signals for the LCD.  You can find thes backpacks on the internet at various vendors and the are about $10.00 US.

                                • 13. Re: I2C  programming ?
                                  user_14586677

                                  Any data you write to the display can also be written out

                                     

                                  over the I2C link. The I2C does not have a clue if it is sending

                                     

                                  LCD data or swamp monster counts, data is data.

                                     

                                   

                                     

                                  The I2C slave receiving the data has to be addressed by the

                                     

                                  master and then data is sent to it. Examples of this are used in

                                     

                                  several of these projects -

                                     

                                   

                                     

                                       

                                     

                                   PSOC 4 element14.com

                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

                                  S No

                                  Date

                                  Project Title

                                  1

                                  01-May-2013

                                  Simple Blinking LED

                                  2

                                  02-May-2013

                                  CapSense Slider Example

                                  3

                                  03-May-2013

                                  PSoC 4 Pioneer Kit Annotation Library

                                  4

                                  06-May-2013

                                  USB-UART utility

                                  5

                                  07-May-2013

                                  USB-I2C Utility

                                  6

                                  08-May-2013

                                  Danger Shield with Light Sensor Control

                                  7

                                  09-May-2013

                                  Danger Shield with 7-segment display

                                  8

                                  10-May-2013

                                  Danger Shield Buzzer of Doom

                                  9

                                  13-May-2013

                                  Graphics LCD Display

                                  10

                                  14-May-2013

                                  LCD - Rotating Cube Demo

                                  11

                                  15-May-2013

                                  GLCD Paddle Game

                                  12

                                  16-May-2013

                                  Pioneer Board Oscilloscope

                                  13

                                  17-May-2013

                                  CapSense Button & LED Control with Bridge Control Panel

                                  14

                                  20-May-2013

                                  What was the value? - LED Memory Example

                                  15

                                  21-May-2013

                                  CapSense Proximity Detection

                                  16

                                  22-May-2013

                                  Proximity Theremin

                                  17

                                  23-May-2013

                                  2-Channel OScope with GraphicsLCD

                                  18

                                  24-May-2013

                                  'Catch the Shells' Game with ColorLCD Shield

                                  19

                                  28-May-2013

                                  LED Memory! Part Deux. Just Deux it!

                                  20

                                  29-May-2013

                                  Starter Designs

                                  21

                                  30-May-2013

                                  Fractional Frequency Synthesizer

                                  22

                                  31-May-2013

                                  “Kill The Ghost” Game

                                  23

                                  03-Jun-2013

                                  tinyprintf Example

                                  24

                                  04-Jun-2013

                                  XBee Router Loopback Example

                                  25

                                  05-Jun-2013

                                  XBee Direct IO

                                  26

                                  06-Jun-2013

                                  XBee API RxTx Example

                                  27

                                  07-Jun-2013

                                  XBee RGB CapSense Control

                                  28

                                  10-Jun-2013

                                  “WiFi? Why Not!” Arduino WiFi Shield Example

                                  29

                                  11-Jun-2013

                                  Bluetooth Home Automation System

                                  30

                                  12-Jun-2013

                                  Bluetooth with GLCD

                                  31

                                  13-Jun-2013

                                  Ethernet Shield

                                  32

                                  14-Jun-2013

                                  More Relay!

                                  33

                                  17-Jun-2013

                                  Sweet Music Everywhere! MIDI Shield

                                  34

                                  18-Jun-2013

                                  Resistive Touch Example

                                  35

                                  19-Jun-2013

                                  UART, I2C, and SPI Joystick Example

                                  36

                                  20-Jun-2013

                                  What? I can use the PSoC 5LP too?

                                  37

                                  21-Jun-2013

                                  PSoC With Friends! Word Scramble Game

                                  38

                                  24-Jun-2013

                                  Ultrasonic Distance Measurement

                                  39

                                  25-Jun-2013

                                  Two PWMs for the price of one

                                  40

                                  26-Jun-2013

                                  Pioneer PnP Sensors

                                  41

                                  27-Jun-2013

                                  Thermistor Example

                                  42

                                  28-Jun-2013

                                  Hangman Game

                                  43

                                  01-Jul-2013

                                  Rise of the Machines (Rolling Robot)

                                  44

                                  02-Jul-2013

                                  Run Away Run Away! (Proximity Robot)

                                  45

                                  03-Jul-2013

                                  Stepper Motor Example

                                  46

                                  05-Jul-2013

                                  “Paint The Night” Accelerometer Example

                                  47

                                  08-Jul-2013

                                  Obstacle Avoider Robot

                                  48

                                  09-Jul-2013

                                  Walk The Line! Robot Example

                                  49

                                  11-Jul-2013

                                  Android Device Controlled Robot

                                  50

                                  12-Jul-2013

                                  SD Card Example

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

                                  S No

                                  Date

                                  Project Title

                                  51

                                  15-Jul-2013

                                  Music Player

                                  52

                                  16-Jul-2013

                                  Strike A Pose! Digital Camera

                                  53

                                  17-Jul-2013

                                  PSoC Eye

                                  54

                                  18-Jul-2013

                                  Custom Component 4x4 Keypad

                                  55

                                  19-Jul-2013

                                  Parallel to Serial UDB Component

                                  56

                                  22-Jul-2013

                                  Accelerometer Level

                                  57

                                  23-Jul-2013

                                  Digital Audio From A Single Pin

                                  58

                                  24-Jul-2013

                                  An Introduction to Processing

                                  59

                                  25-Jul-2013

                                  But Wait There’s More! Single PWM with 3 Outputs

                                  60

                                  26-Jul-2013

                                  PSoC 4 Mini-Billboard

                                  61

                                  29-Jul-2013

                                  Nokia 5110 LCD Interface

                                  62

                                  30-Jul-2013

                                  Ready…Set…GO! PSoC Stopwatch

                                  63

                                  31-Jul-2013

                                  Some Like it Hot! PSoC Thermostat

                                  64

                                  01-Aug-2013

                                  Workspace Organization using PSoC Theromostat

                                  65

                                  02-Aug-2013

                                  New to PSoC or the Pioneer Kit? START HERE!

                                  66

                                  05-Aug-2013

                                  LED Blinky Revisited

                                  67

                                  06-Aug-2013

                                  PSoC 4 Getting Started Lab 1 (LED Blinky)

                                  68

                                  07-Aug-2013

                                  PSoC 4 Getting Started Lab 2 (PWM LED)

                                  69

                                  08-Aug-2013

                                  PSoC 4 Getting Started Lab 3 (CapSense UART)

                                  70

                                  09-Aug-2013

                                  PSoC 4 Getting Started Lab 4 (ADC)

                                  71

                                  12-Aug-2013

                                  Get Your Motor Runnin’!

                                  72

                                  13-Aug-2013

                                  TFT Touchscreen Shield

                                  73

                                  14-Aug-2013

                                  TFT Touchscreen Tic-Tac-Toe Game

                                  74

                                  15-Aug-2013

                                  PSoC Creator Training 110

                                  75

                                  16-Aug-2013

                                  PSoC Creator Training 111                                          

                                  76

                                  19-Aug-2013

                                  PSoC Creator Training 112

                                  77

                                  20-Aug-2013

                                  PSoC Creator Training 113

                                  78

                                  21-Aug-2013

                                  PSoC Creator Training 210

                                  79

                                  22-Aug-2013

                                  PSoC Creator Training 211

                                  80

                                  23-Aug-2013

                                  PSoC Creator Training 212/213/214

                                  81

                                  26-Aug-2013

                                  NFC/RFID Shield

                                  82

                                  27-Aug-2013

                                  RFID Reader and Writer Project #2

                                  83

                                  28-Aug-2013

                                  Raspberry Pi Integration

                                  84

                                  29-Aug-2013

                                  State Machines in PSoC 4

                                  85

                                  30-Aug-2013

                                  UART Bootloader in PSoC 4

                                  86

                                  03-Sep-2013

                                  GPS Algorithm

                                  87

                                  04-Sep-2013

                                  Gas Sensor Example

                                  88

                                  05-Sep-2013

                                  Simulation of Gas Sensor Example

                                  89

                                  06-Sep-2013

                                  GPS Example

                                  90

                                  09-Sep-2013

                                  Comparator Example

                                  91

                                  10-Sep-2013

                                  Infrared Remote Control

                                  92

                                  11-Sep-2013

                                  Serial Communications Examples

                                  93

                                  12-Sep-2013

                                  4 Channel Multiplexed Comparator

                                  94

                                  13-Sep-2013

                                  Opamp Dynamic Gain

                                  95

                                  16-Sep-2013

                                  Hibernate and Stop Power Modes

                                  96

                                  17-Sep-2013

                                  P4 Light Sensor Project Design

                                  97

                                  18-Sep-2013

                                  Rice Cooker

                                  98

                                  19-Sep-2013

                                  Thermal Printer

                                  99

                                  20-Sep-2013

                                  I2C Pass Though 'Smart Wire'

                                  100

                                  23-Sep-2013

                                  PSoC 4 Time Square Billboard

                                  • 14. Re: I2C  programming ?
                                    user_14586677

                                    As long as you mapped the LCD pins to the correct port

                                       

                                    pin ordering you are OK. Rename the PSOC port pins to

                                       

                                    correspond to the LCD pin name, makes it easy to keep

                                       

                                    track of.

                                       

                                     

                                       

                                     

                                       

                                     

                                       

                                    Also you have to connect LCD power and ground. And connect contrast pin on LCD to a pot.

                                       

                                    Nominally set it to Vdd / 2 then adjust for best display appearance.

                                       

                                     

                                       

                                    1 2 3 Previous Next