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. ?
2. Writes data over I2C
4. start I2C
5. Reads data from I2C
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.
Although this video is for PSOC 1 the basic principles the same -
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"
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. send data to LCD
4. LCD _PrintString()
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
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.
The basic protocol is a start/stop -
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.
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.
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.
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.
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.
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.
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.
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??
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
The above componnet uses one contiguous port to connect. If you
need to spread across multiple ports the connections see Kees
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!!
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
how to send data on LCD via I2C communication ?
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-a... 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
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
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
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.
first I opend psoc creator than I opened sample project for LCD. after that I opend CharLCD_Custom font project. I have done this program successfuly. I can see text on LCD
Now I want to use same Project but at this time I want to display text on LCD via i2c. so I added I2C component , I think main problem is program. I did not wrote any function for I2c I have to make program that send data on LCD
I want to ask where I am making mistake in program or design?
Please look at my project workspace that I posted in my previous post.
You would add an I2C Slave to your project.
There is an example project you can look at that transfers
data to a PSOC over I2C - the SCB_I2cCommSlave or SCB_EzI2cCommSlave projects
ok after reading some material. I wrote some code I am not sure It will work
extern uint8 const CYCODE LCD_customFonts;
/* Enable global interrupts - required for I2C */
/* The I2C will start */
/*  END OF FILE */
I am sending data on LCD via i2c.
I have connected all pins.
I don't understand where to connect SDLP4[ 0]and SCL P4 ?
also tell me about program that I have been posted ?
Vead I do not think you understand what I2C is. I2c is a communications buss from a master unit to a Slave unit. . You do not have a device connected to you I2C buss that is transmitting the data. Such as a DS1307 serial real-time clock (RTC) or some other device that is outputting data and then it is sent to the PSOC 4 and the PSOC 4 receives the data and then displays it on the LCD. You need to have the addresses for the I2C devices and that has to be in the program.
Here are some I2C devices are you using any of these in your project? You also need the data sheet for your device so you can get the address and other commands and data information.
MAX6956 20-Port LED Display Driver and digital I/O Expander constant current sink, up to 16 Devices, Interrupt
MAX6953 4 Digit Matrix LED Driver, up to 140 LEDs
MAX127/MAX128 octal 12 Bit DAC
MAX521 Octal 8 Bit DAC
MAX 1036/1037 4-channel 8-bit ADC, single supply (5V / 3.3V)
MAX 1038/1039 12-channel 8-bit ADC, single supply (5V / 3.3V)
MCP23016 16-bit I/O Port Expander
MCP23017 16-bit I/O Port Expander
MCP23008 8-bit I/O Port Expander
MCP3021 10 bit ADC, one channel
MCP3221 12 bit ADC, one channel
MCP3421 18 bit ADC, one channel
MCP4725 12 bit ADC, one channel
TC1320 8 bit ADC, one channel
TC1321 10 bit ADC, one channel
NS73M FM Transmitter (source: sparcfun.com) I2C maybe problematic?
PCA 9533 4-bit LED dimmer (8-bit PWM) suitable for H-Bridges (L293D)
PCA 9531 8-bit LED dimmer (8-bit PWM)
PCA 9532 16-bit LED dimmer (8-bit PWM)
PCF 8566 96 segment LCD driver
PCF 8568 LCD Row driver for dot matrix displays.
PCF 8569 LCD Column driver for DOT matrix displays
PCF 8576 160 segment LCD driver
PCD 8577 64 Segment LCD driver
PCF 8578 LCD Row driver for Dot matrix LCD's
PCD 8579 Column driver for Dot matrix LCD's
SAA 1064 4 Digit Led driver
PCF 8574 8 Bit I/O port
PCF 8574A 8 Bit I/O port different address.
SAA 1300 5 Bit high current driver
PCF 8591 4 channel ADC + One DAC (all 8 bits)
TDA 8442 Quad 6 bit DAC
TDA 8444 Octal 6 bit DAC
PCF 8570 256 byte static ram
PCf 8571 128 byte static ram
PCF 8581 128 byte EEprom
PCF 8582 256 byte EEprom
PCF 8583 256 byte RAM + Realtime clock and calendar
PCF 8594 512 byte EEprom
PCF 8598 1K byte EEprom
PCF 8573 Clock/Calendar
PCF 8583 Clock/Calendar with 256 byte Ram
Audio / Video:
PCD3311 3312 DTMF / Tone generator
SAA1136 PCM interface
SAA524x Teletext processor
SAA7191 S-VHS decoder
SAA7192 Digital color space converter
SAA7199 Digital encoder
SAA9020 Field memory controller
SAA9051 Digital TV decoder
SAA9068 PIPCO Picture in picture system
SAB3035 3037 Tuning interface
SAF1135 VPS decoder
TDA4680 Video processor
TDA8421 HiFi stereo audio processor
TDA8425 Audio processor with loudspeaker channel
TDA8440 Video switch
TDA8442 Color decoder interface
TDA8443 YUV to RGB unit
TDA8461 PAL / NTSC color decoder
TEA6100 Fm tuning interface
TEA6300 6310 Sound fader control
TSA551x TV Pll synthesizer
TSA6057 Fm Pll synthesizer
SAA1300 5 bit high current driver
UMF1009 Frequency synthesizer
SDA3312 TV PLL synthesizer
SDA2121 TV PLL synthesizer
SDA2516 1K bit EEprom
SDA2526 2K bit EEprom
SDA2546 4K bit EEprom
SDA2586 8K bit EEprom
SDA3526 2K bit EEprom with write protection
SDA3546 4K bit EEprom with write protection
SDA3586 8K bit EEprom with write protection
M41T00S RTC w. 64b (8 x 😎
M41T00SC6430 RTC w. Embedded Crystal; 64Kb (8192 x 8); w. EEPROM
M41T11 28 RTC w. BATTERY; 512b (64 x 8);
M41T56 512b RTC w. (64 x 8); SRAM
M41T56C64 RTC w. Embedded Crystal; 64Kb (8192 x 8); w. EEPROM
M41T00 RTC w. 64b (8 x 😎
M41ST84W RTC w. 512b (64 x 8); RTC SUPERVISOR
M41ST85W RTC w. BATTERY; with Embedded Crystal; 512b (64 x 8); RTC SUPERVISOR
M41ST87W RTC w. Embedded Crystal; 1280b (160 x 8); RTC SUPERVISOR
M41ST87Y RTC w. with Embedded Crystal; 1280b (160 x 8); RTC SUPERVISOR
M41T0 RTC w. 64b (8 x 😎
M41T60 RTC w. 64b (8 x 😎
M41T62 RTC w. 128b (16 x 8); with Alarms
M41T65 RTC w. 128b (16 x 8); with Alarms
M41T80 RTC w. 160b (20 x 8); with Alarms
M41T81S RTC w. Embedded Crystal; 160b (20 x 8); with Alarms
M41T82 RTC w. 256b (32 x 8), Battery Switchover
M41T83 RTC w. Embedded Crystal 256b (32 x 8), Battery Switchover
M41T256Y RTC w. BAT Cu wo/socket 256Kb (32K x 😎
M41T81 RTC w. 160b (20 x 😎
M24C01-R 1 kbit EEPROM
M24C01-W 1 kbit EEPROM
M24C02-R 2 kbit EEPROM
M24C02-W 2 kbit EEPROM
M24C04-R 4 kbit EEPROM
M24C04-W 4 kbit EEPROM
M24C08-R 8 kbit EEPROM
M24C08-W 8 kbit EEPROM
M24C16-R 16 kbit EEPROM
M24C16-W 16 kbit EEPROM
M24C32-F 32 kbit EEPROM
M24C32-R 32 kbit EEPROM
M24C32-W 32 kbit EEPROM
M24C64-R 64 kbit EEPROM
M24C64-W 64 kbit EEPROM
M34D64-W 64 kbit EEPROM
M24128-BR 128 kbit EEPROM
M24128-BW 128 kbit EEPROM
M24256-BR 256 kbit EEPROM
M24256-BW 256 kbit EEPROM
M24512-R 512 kbit EEPROM
M24512-W 512 kbit EEPROM
M24M01-R 1000 kbit EEPROM
LIS3LV02DL Linear Accelerometer 3-Axis ±2g/ ±6g with digital interface
LIS3LV02DQ Linear Accelerometer 3-Axis ±2g/ ±6g Full Scale with digital interface
TLV320AIC3101 6 Inputs, 6 Outputs, Speaker & Headphone Amp., Enh. Digital Effects, PowerTune
P82B96 Dual Bidirectional Bus Buffer
PCA6107 Remote 8-Bit Low-Power I/O Expander With Interrupt Output, Reset, and Config Registers
PCA9534 Remote 8-Bit Low-Power I/O Expander with Interrupt Output and Configuration Registers
PCA9534A Remote 8-Bit Low-Power I/O Expander with Interrupt Output and Configuration Registers
PCA9535 Remote 16-Bit Low-Power I/O Expander With Interrupt Output and Config Registers
PCA9536 Remote 4-Bit I/O Expander with Configuration Registers
PCA9538 Remote 8-Bit Low-Power I/O Expander With Interrupt Output, Reset, and Config Registers
PCA9539 Remote 16-Bit Low-Power I/O Expander With Interrupt Output, Reset & Config. Registers
PCA9554A Remote 8-Bit I/O Expander with Interrupt Output and Configuration Registers
PCA9555 Remote 16-Bit I/O Expander With Interrupt Output And Configuration Registers
PCA9557 Remote 8-Bit Low-Power I/O Expander with Reset and Configuration Registers
PCF8574 Remote 8-Bit I/O Expander
PCF8574A Remote 8-Bit I/O Expander
PCF8575 Remote 16-Bit I/O Expander with Interrupt Output
PCF8575C Remote 16-Bit I/O Expander with Interrupt Output
TCA6408 Low-Voltage 8-Bit I/O Expander With Interrupt Output, Reset, and Config Register
PCA8550 Non-Volatile 5-Bit Registered Multiplexer with I2C Interface
PCA9544A 4-Channel I2C And SMBus Multiplexer With Interrupt Logic
PCA9545A 4-Channel I2C And SMBus Multiplexer With Interrupt Logic And Reset Functions
PCA9546A 4-Channel I2C And SMBus Multiplexer With Reset Functions
PCA9306 Dual Bi-Directional I2C-Bus and SMBus Voltage Level-Translator
PCA9515A Dual Bidirectional I2C Bus and SMBus Repeater
PCA9518 Expandable Five-Channel I2C Hub
PCA9543A Two-Channel I2C-Bus Switch With Interrupt Logic and Reset
PCA9548A 8-Channel I2C Switch With Reset
TCA6507 Low-Voltage 7-Bit I2C and SMBus LED Driver With Intensity Control and Shutdown
X24C01 1k bit EEprom
X24012 1k bit EEprom
X24C02 2k bit EEprom
X24022 2k bit EEprom
X24C04 4k bit EEprom
X24042 4k bit EEprom
X24C08 8k bit EEprom
X24C16 16k bit EEprom
X24164 16k bit EEprom
X24X00 128 bit EEprom
X24001 128 bit EEprom
Vead You do not need the I2C component for the Psoc RTC component as it is all done in software. The I2c is used for a DS1307 device or RTC board that has an I2C communication port. The Psoc RTC does not have a crystal to keep it on time so it looses about 5 minutes a day. The DS1307 has the crystal clocks and is very accurate. So if you are using the PSOC RTC component you do not need the I2C component.
there seem to be some lacks of information or understanding of what you want to perform.
Can you send us a picture / drawing (Block Diagram) of all the components you want to use (PSocS, LCDs RTCs) and how you want to wire them. This will probably express more easy to understand what you'd like to do.
1. Psoc 4 (cy8ckit -049-42xx)
2. LCD JHD 16 2 A
*LCD is used to display date , time month year
* DS1307 is used to set alarm for second , minute day month
Psoc 4 will receive data form ds1307 and send data to LCD
after that I created design
I don't understand why bobgoar said I don't need to use I2c ? I am just turning around and around so please tell me What I need to do ?
Well, that is more a BoM (Bill of material) than a block diagram.
But what I can see instatly is: You have forgotten something:
You will need a means to initially set the clock and later specify the alarm-times.
When these times are to be changed by a user as in an alarm-clock you will need something like a keypad, when it shall be changed by a machine (computer) you will need an interface between your PSoC4 and the machine. Nonetheless in that configuration there will be a keypad or keyboard connected to that machine.
Since the DS1307 is not capable to handling daylight-saving-time you will put some thoughts into that problem, too.
Professional developers start by writing a "Functional Specification Document" (FSD) which gives in written form everything the device under construction shall perforn. This document is usually signed with blood as a contract between the customer and the developer. Do not think that this document is not needed for your case, since you haven't got a customer! This document will help you to see the project more clearly, viewing at it from the end-user's side, not from the developer's side only.
Next step usually is (when hardware is envolved) a block-diagram showing the connections of the required components. Here you already can specify known facts as the I2C-connection of DS1307 with 0x68 being the slave address of that chip and using PSoC4 pins P4 and  which additionally will need some pull-up resistors (~5k) for I2C to function correctly.
So, what is your decision: How to enter times for alarm set?
You did not comment on
Keypad to enter data
Daylight saving time (DST)
I can roughly see what you want to do, but what for? Do you want to build an alarm-clock?? An automated garden watering system???
Although a buzzer seems to be something very simple, electric connection can be something difficult.
So to be clear you have two possible approaches.
1) Use software RTC component in PSOC, DS1307 not used.
2) Use external RTC with I2C communications between PSOC and DS1307
If battery life is paramount then using PSOC with internal osc and using sleep
mode way to go with external DS1307 managed over I2C link.
If cost paramount then PSOC only using RTC component. DS1307 not used.
1) Use software RTC component in PSOC, DS1307 not used.
does it work without ds1307. can we generate log delay for month year without ds1307 (hardware Ic)
2. 2) Use external RTC with I2C communications between PSOC and DS1307
pin 1 is output pin for valve
Yes, that's it.
PSoC may be able to run for years, but will your power-supply be stable for all the time?
External RTC will run on batt when power loss, to have PSoC batt buffered there is a bit more electronic needed.
PS: When your Pin_1 is controlling the valve, why don't you name that pin "WaterValve" or something meaningful?
Vead I don't see anyway out of not using a keyboard to set the alarm time. . If you do not want to have a mechanical keyboard use a Capsense keyboard or a touch screen LCD and it can server a dual purpose of display and keyboard entry . The Capsense would be best as it is not affected by water droplets as this is a watering device. Bob is right a block diagram and schematic would be very helpful for starting the design.This project will require quite a lot of code.
Hi vead 🙂
I have tried project with i2c communication. The PSoC master read an ADC and the PSoC slave display the ADC count in LCD. I will post it soon in this thread to show a complete step about my project.
you may look at the "Notice" tab to get explanations for the error, in your case "Invalid number of parameters". So look into the RTC-datasheet and find the appropiate API to see what and what kind of parameters are expected.
here are the function of RTC datasheet
of this datasheet for more information, as needed.
RTC_Start() // Starts the RTC_P4 component by initializing all the parameters and registers
RTC_Stop() // Stops RTC_P4 component operation
RTC_SetDateAndTime() //Sets time and date values
RTC_SetAlarmDateAndTime() // Sets the alarm time and date values
I put the same function in program
/* Set date and time */
/* Set alarm date and time */
/* Set alarm mask */
Build error: too few arguments to function 'RTC_SetDateAndTime'
Build error: too few arguments to function 'RTC_SetAlarmDateAndTime'
Build error: too few arguments to function 'RTC_SetAlarmMask'
what ismeaning of ''too few arguments to function'' also I am reading some forum post and I am trying to understand where I am doing mistake
I saw some sample project after that I wrote program. please look at this program and tell me whats wrong
/* Time: 02:59:50 */
#define TIME_HOUR (0x02u)
#define TIME_MIN (0x59u)
#define TIME_SEC (0x50u)
#define HOUR_OFFSET (16u)
#define MIN_OFFSET (8u)
#define TIME_HR_MIN_SEC ((uint32)(TIME_HOUR << HOUR_OFFSET) | \
(uint32)(TIME_MIN << MIN_OFFSET) | \
/* Date: 05/16/2015 */
#define DATE_MONTH (RTC_MARCH)
#define DATE_DAY (0x16u)
#define DATE_YEAR (0x2015u)
#define MONTH_OFFSET (24u)
#define DAY_OFFSET (16u)
#define DATE_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << MONTH_OFFSET) | \
(uint32)(DATE_DAY << DAY_OFFSET) | \
/* Alarm Time: 15:44:00 */
#define ALARM_HOUR (0x04u)
#define ALARM_MIN (0x01u)
#define ALARM_SEC (0x30u)
#define ALARM_TIME_HR_MIN_SEC ((uint32)(ALARM_HOUR << HOUR_OFFSET) | \
(uint32)(ALARM_MIN << MIN_OFFSET) | \
/* Alarm Date: 06/16/2015 */
#define ALARM_DATE_MONTH_DAY_YEAR (DATE_MONTH_DAY_YEAR)
/* Alarm structure declaration */
/* Alarm flag initialization */
uint32 alarmFlag = 0;
/* Alarm structure initialization */
alarmTimeDate.time = ALARM_TIME_HR_MIN_SEC;
alarmTimeDate.date = ALARM_DATE_MONTH_DAY_YEAR;
/* Starts RTC component */
/* Set Date and Time */
/* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
/* Place your application code here. */
/*  END OF FILE */