03:00 - I2C Overview 08:00 - Data transfer 19:54 - Control and Status register 44:00 - Common issues 58:15 - Demo 1:26:00 - Troubleshooting 1:29:30 - summary
This is great. I was tired of quick videos that really didn't get to the core. I want to UNDERSTAND THE PROTOCOL not just install random libraries and pray lol.
@@MicrochipTechnology That woman telephone operator at bangalore is totally unprofessional & doesn't know how to deal with people. I had called on 08030904444 regarding some queries but she totally behaved in an uncivilized manner. It will be better if there is some professional person instead of her
37:58 "by default it is disabled..." but as it's seen from the slide by default bit value is ZERO and in the definition this enables the feature. Though it is interesting that a CLEAR bit enable a feature ? . So either slide or instructor may be wrong.
Thank you for pointing that out. It is indeed clear (0) by default. This means it is enabled. We checked the datasheet, which is the recommended approach when faced with conflicting ideas. The most recent information is in the datasheet. Thank you for attending this class and paying careful attention to the presentation.
This is a nice video but there's one more question to add to your video description... "why every explanation is given in C? Some of us would like to (as long as you are explaining i2c fundaments) know how to use i2c in assembly code", otherwise MCC will solve the code requisitions... and by the way, mnemonics are the closest way to "talk" with PIC's. It would be awesome if you could please explain how to configure it in ASM, with the new xc8 pic-as (wich is completely diferent and hard to addapt previous codes, i'm still trying to understand the new "psect udata udatashare code class=code... etc") it would be so usefull a nice explanation like this. Thanks :)
Address sent by master always a write command. Data could be an uint8_t or uint16_t so 1 or 2 bytes. To store someting after that is a restart and data1 data2 data3.... so on untill stop. You can send 1st a read command without address write. It is the read current address command. Pointer of the slave device is somewhere (maybe the last position of last accomplished i2c process).
void eepromWrite (char slaveAddress, char Addhigh, char AddLow, char eeData); char eepromread (char slaveAddress, char Addhigh, char AddLow); // slave address is the address byte (slave address +r/w bit) // addHigh is the eeprom Address high bye // eedata is the data to be written in the slave volatile char ReadData; // global variable for monitoring. void main(void) { int x; //general purpose variable OSCCONbits.IRCF = 12 /// 2MHZ clock ANSELB = 0; // All portB pins are digital TRISBbits.TRISB0=0; // RB0 is output. LATBbits.LATB0 = 1; // LED indicator to know that code is running. SSPADD = 4; // 100khZ i2c CLOCK WITH fOSC = 2 mhZ // i2c CLOCK = fOSC/ (4*(sspadd+1)) sspcon1 = 0X28 // sspm = 1000 (i2c mASTER) // sspen = 1 (i2c module is enabled) eepromWrite (0xA0, 0x12, 0x34, 0x78); for (x=1; x
This part of C code is needed and missing at the end of write_I2C(..) function ! or Is-it ?? I tested the read & write I2C functions using a PCF8563 I2C Real Time Clock and noticed some of the RTC registers was uncorrectly written by the write_I2C() function. The read_I2C(...) function though was correctly reading any of the RTC registers. So I had a look at the write_I2C() function and check the START, ACK, NACK and STOP flags and where they were installed in the function.. And I remembered the Microchip teacher talked about a NACK flag sent from the PIC master to the slave EEPROM at the end of the read_I2C() function telling it 'I don't need any data anymore' so the slave could correctly end up the I2C transmission.. Since the RTC and the EEPROM can be accessed one register at a time or with a sequential datas sent or read from a starting address it make sense the NACK should be sent at the end of both write_I2C() and read_I2C() functions right ? So the read_I2C() function had a NACK flag sent to the slave at the end of its code, but the write_I2C() did not ! See part of the write_I2C() end below and see the added NACK code. After this code added to the write_I2C's end I could now correctly write ANY values to the RTC registers and read them back with equal values. Maybe I forgot something in my added code here and I'm not doing things right but the RTC communication now works perfectly. (PIC16F877, Pullup res of 4K7 and I2C speed @ 100Khz) Jean-Pierre Desrochers. /////////////////////////////////////////////// void write_I2C(unsigned char slaveAddress, unsigned char Address, unsigned char Data) { SSPCON2bits.SEN = 1; // initiate start condition while(SEN); PIR1bits.SSPIF = 0; // clear SSP interrupt flag SSPBUF = slaveAddress; // send slave address and R/W bit while(!SSPIF); // wait for ack. SSPIF is set every 9th clock cycle. PIR1bits.SSPIF = 0; // clear SSP interrupt flag if(SSPCON2bits.ACKSTAT) { SSPCON2bits.PEN = 1; // initiate stop condition while(PEN); // wait for start to complete return; // exit write (No ack) cause no slave replied ! } SSPBUF = Address; // send slave address and R/W bit while(!SSPIF); // wait for ack. SSPIF is set every 9th clock cycle. PIR1bits.SSPIF = 0; // clear SSP interrupt flag if(SSPCON2bits.ACKSTAT) { SSPCON2bits.PEN = 1; // initiate stop condition while (PEN); // wait for start to complete return; // exit write (No ack) cause no slave replied ! } SSPBUF = Data; // send slave address and R/W bit while(!SSPIF); // wait for ack. SSPIF is set every 9th clock cycle. PIR1bits.SSPIF = 0; // clear SSP interrupt flag if(SSPCON2bits.ACKSTAT) { SSPCON2bits.PEN = 1; // initiate stop condition while(PEN); // wait for start to complete return; // exit write (No ack) cause no slave replied ! } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This part of C code is needed and missing at the end of write_I2C(..) function. // else // { // SSPCON2bits.ACKDT = 1; // Prepare to send NACK
Hi there, thanks for reaching out. To get started, you’ll need to configure your MCU with some basic steps. Setup Configuration Bits: Configure the oscillator, watchdog timer, power-up timer, and low-voltage programming in MPLAB X. Use MPLAB Code Configurator (MCC) for easier setup. Some basic example code is here: #include #define _XTAL_FREQ 20000000 void main() { TRISB = 0x00; // Set PORTB as output while(1) { LATBbits.LATB0 = 1; // Turn on LED connected to RB0 __delay_ms(500); LATBbits.LATB0 = 0; // Turn off LED __delay_ms(500); } } This is to toggle an LED. We hope this helps! If you need more technical guidance, reach out to Microchip.com/CSS.
@@MicrochipTechnology I know how to toogle a led. The pic16f687 doesn't have MCC, the least it has is bits configuration and it's XTAL_FREQ is 8000000. It's like I said, some microcontrollers have a bad documentation
Hello and thanks for your question! LVDS is supported in the SmartFusion2 M2S025-FG484. Please contact Microchip’s FPGA design partners to learn how to write Verilog code for LVDS implementation: www.microchip.com/en-us/products/fpgas-and-plds/fpga-design-resources/fpga-design-partners. We also offer SmartFusion and SmartFusion2 simulation library source files here: microchipsupport.force.com/s/article/SmartFusion-and-SmartFusion2-VHDL-simulation-library-source-files-support-1625098162917 Please let us know if this helps!
Hi Aleksa, this application note might be helpful for you: ww1.microchip.com/downloads/en/Appnotes/MPLAB-Code-Configurator-CAN2.0B-Module-For-PIC18-00002714A.pdff
I am trying to send a data from the PC using the uart save it in memory and then read from the memory and write again using the uart to display it on the pc. I have used several codes and the problem persists. I send an "a" or "01100001" and receive two bytes "00000000 00111111". Any idea what it could be? I used your code
I tried mcc (code configurator) simple master and eeprom example. Both worked but eeprom example is much better. It is a while (blocked) triggered but accomplised to made self state machine non blocking style.
Hi there, thank you for your feedback! We appreciate it and will pass it along to our product team. They will take it into consideration as they strive to enhance our code examples and software libraries.
@@MicrochipTechnology That woman telephone operator at bangalore is totally unprofessional & doesn't know how to deal with people. I had called on 08030904444 regarding some queries but she totally behaved in an uncivilized manner. It will be better if there is some professional person instead of her
This is the best I2C presentation I've ever seen. Thank you!
03:00 - I2C Overview
08:00 - Data transfer
19:54 - Control and Status register
44:00 - Common issues
58:15 - Demo
1:26:00 - Troubleshooting
1:29:30 - summary
This is the best explanation of i2c I ever saw :):)
Wish you to do the similar session for spi too
great presentation, this class help me a lot for understanding i2c
Love the way presentation is being presented.
Congratzz for this video. biomedical engineering student. Universidad autonoma de baja california
thanks for this course. it would be great if you can include more code examples to write / read and configure registers
This is the best presentation about I2C available on internet. Thank you too!
Thanks for a well presented video.
This is great. I was tired of quick videos that really didn't get to the core. I want to UNDERSTAND THE PROTOCOL not just install random libraries and pray lol.
Very informative video on i2c. Thanks Microchip !
The best course about I2C i ever found. Thank you !
Wonderfully explained. Thanks a lot.
Excellent! Where can we find the souce code?
Great lecture. Thank you.
Great training. Thank you!
Thank you! Great I2C training.
Please share demo.c file or zip file to understand function
very nice presentation~ but is there any way that i can download the power point? thank you
what's the reason behind the second ACK pin?
And thanks for the video this was one of the best explanation ever found on TH-cam.
@Aayush Dev - Can you please point us to a specific time stamp in the video to help us best answer your question? Thank you!
@@MicrochipTechnology 16:26 immediately after the data is sent, it can be seen there is one more ACK .
@@MicrochipTechnology
That woman telephone operator at bangalore is totally unprofessional & doesn't know how to deal with people. I had called on 08030904444 regarding some queries but she totally behaved in an uncivilized manner. It will be better if there is some professional person instead of her
37:58 "by default it is disabled..." but as it's seen from the slide by default bit value is ZERO and in the definition this enables the feature. Though it is interesting that a CLEAR bit enable a feature ? . So either slide or instructor may be wrong.
Thank you for pointing that out. It is indeed clear (0) by default. This means it is enabled. We checked the datasheet, which is the recommended approach when faced with conflicting ideas. The most recent information is in the datasheet. Thank you for attending this class and paying careful attention to the presentation.
This is a nice video but there's one more question to add to your video description... "why every explanation is given in C? Some of us would like to (as long as you are explaining i2c fundaments) know how to use i2c in assembly code", otherwise MCC will solve the code requisitions... and by the way, mnemonics are the closest way to "talk" with PIC's. It would be awesome if you could please explain how to configure it in ASM, with the new xc8 pic-as (wich is completely diferent and hard to addapt previous codes, i'm still trying to understand the new "psect udata udatashare code class=code... etc") it would be so usefull a nice explanation like this. Thanks :)
"I always read 0xFF. What is wrong?", Please verify the return statement on EEpromread function it returns 0XFF, that is why you always read 0xFF.
Thanks for your help.
Activation of subtitles, contributions to learning, globally.
Nice video.. will u plz make one on spi protocol too.. it will be too helpful for students
Excuse me. Can you help me with an addres when I can find courses for study presentially in Microchip. Thanks
when transmitting the address and next data how the slave is treating it is addressed and it is data after acknowledgment how data is recognized
Address sent by master always a write command. Data could be an uint8_t or uint16_t so 1 or 2 bytes. To store someting after that is a restart and data1 data2 data3.... so on untill stop. You can send 1st a read command without address write. It is the read current address command. Pointer of the slave device is somewhere (maybe the last position of last accomplished i2c process).
Can I attend this class or can I join with your company
Kindly visit this site for Microchip MASTERs events and to register: techtrain.microchip.com/masters/Home.aspx
Would it be possible to publish the i2C_demo.c program? I would be very grateful
void eepromWrite (char slaveAddress, char Addhigh, char AddLow, char eeData);
char eepromread (char slaveAddress, char Addhigh, char AddLow);
// slave address is the address byte (slave address +r/w bit)
// addHigh is the eeprom Address high bye
// eedata is the data to be written in the slave
volatile char ReadData; // global variable for monitoring.
void main(void)
{
int x; //general purpose variable
OSCCONbits.IRCF = 12 /// 2MHZ clock
ANSELB = 0; // All portB pins are digital
TRISBbits.TRISB0=0; // RB0 is output.
LATBbits.LATB0 = 1; // LED indicator to know that code is running.
SSPADD = 4; // 100khZ i2c CLOCK WITH fOSC = 2 mhZ
// i2c CLOCK = fOSC/ (4*(sspadd+1))
sspcon1 = 0X28 // sspm = 1000 (i2c mASTER)
// sspen = 1 (i2c module is enabled)
eepromWrite (0xA0, 0x12, 0x34, 0x78);
for (x=1; x
This part of C code is needed and missing at the end of write_I2C(..) function ! or Is-it ??
I tested the read & write I2C functions using a PCF8563 I2C Real Time Clock
and noticed some of the RTC registers was uncorrectly written by the write_I2C() function.
The read_I2C(...) function though was correctly reading any of the RTC registers.
So I had a look at the write_I2C() function and check the START, ACK, NACK and STOP flags
and where they were installed in the function..
And I remembered the Microchip teacher talked about a NACK flag sent from the PIC master
to the slave EEPROM at the end of the read_I2C() function telling it
'I don't need any data anymore' so the slave could correctly end up the I2C transmission..
Since the RTC and the EEPROM can be accessed one register at a time
or with a sequential datas sent or read from a starting address
it make sense the NACK should be sent at the end of both write_I2C() and read_I2C() functions right ?
So the read_I2C() function had a NACK flag sent to the slave at the end of its code,
but the write_I2C() did not !
See part of the write_I2C() end below and see the added NACK code.
After this code added to the write_I2C's end I could now correctly write ANY values
to the RTC registers and read them back with equal values.
Maybe I forgot something in my added code here and I'm not doing
things right but the RTC communication now works perfectly.
(PIC16F877, Pullup res of 4K7 and I2C speed @ 100Khz)
Jean-Pierre Desrochers.
///////////////////////////////////////////////
void write_I2C(unsigned char slaveAddress, unsigned char Address, unsigned char Data)
{
SSPCON2bits.SEN = 1; // initiate start condition
while(SEN);
PIR1bits.SSPIF = 0; // clear SSP interrupt flag
SSPBUF = slaveAddress; // send slave address and R/W bit
while(!SSPIF); // wait for ack. SSPIF is set every 9th clock cycle.
PIR1bits.SSPIF = 0; // clear SSP interrupt flag
if(SSPCON2bits.ACKSTAT)
{
SSPCON2bits.PEN = 1; // initiate stop condition
while(PEN); // wait for start to complete
return; // exit write (No ack) cause no slave replied !
}
SSPBUF = Address; // send slave address and R/W bit
while(!SSPIF); // wait for ack. SSPIF is set every 9th clock cycle.
PIR1bits.SSPIF = 0; // clear SSP interrupt flag
if(SSPCON2bits.ACKSTAT)
{
SSPCON2bits.PEN = 1; // initiate stop condition
while (PEN); // wait for start to complete
return; // exit write (No ack) cause no slave replied !
}
SSPBUF = Data; // send slave address and R/W bit
while(!SSPIF); // wait for ack. SSPIF is set every 9th clock cycle.
PIR1bits.SSPIF = 0; // clear SSP interrupt flag
if(SSPCON2bits.ACKSTAT)
{
SSPCON2bits.PEN = 1; // initiate stop condition
while(PEN); // wait for start to complete
return; // exit write (No ack) cause no slave replied !
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This part of C code is needed and missing at the end of write_I2C(..) function. //
else //
{ //
SSPCON2bits.ACKDT = 1; // Prepare to send NACK
Sir, PIC 16F877A is readable by pickit2, but writing is not working. in one ic, what is the problem? is ic repairable.
In this case, please submit a support case here:
microchipsupport.force.com/s/communityknowledge
my pic16f687 hasn't many of these registers and there's no example on the datasheet. How can I know what to do to start it on the right way?
Hi there, thanks for reaching out. To get started, you’ll need to configure your MCU with some basic steps. Setup Configuration Bits: Configure the oscillator, watchdog timer, power-up timer, and low-voltage programming in MPLAB X. Use MPLAB Code Configurator (MCC) for easier setup.
Some basic example code is here:
#include
#define _XTAL_FREQ 20000000
void main() {
TRISB = 0x00; // Set PORTB as output
while(1) {
LATBbits.LATB0 = 1; // Turn on LED connected to RB0
__delay_ms(500);
LATBbits.LATB0 = 0; // Turn off LED
__delay_ms(500);
}
}
This is to toggle an LED. We hope this helps! If you need more technical guidance, reach out to Microchip.com/CSS.
@@MicrochipTechnology I know how to toogle a led. The pic16f687 doesn't have MCC, the least it has is bits configuration and it's XTAL_FREQ is 8000000. It's like I said, some microcontrollers have a bad documentation
How to write Verilog code for LVDS implementation into M2S025-FG484 FPGA board. Is LVDS incompatible with this board
Hello and thanks for your question! LVDS is supported in the SmartFusion2 M2S025-FG484. Please contact Microchip’s FPGA design partners to learn how to write Verilog code for LVDS implementation: www.microchip.com/en-us/products/fpgas-and-plds/fpga-design-resources/fpga-design-partners.
We also offer SmartFusion and SmartFusion2 simulation library source files here: microchipsupport.force.com/s/article/SmartFusion-and-SmartFusion2-VHDL-simulation-library-source-files-support-1625098162917
Please let us know if this helps!
Do you have something like that for CAN protocol in MCC?
Hi Aleksa, this application note might be helpful for you: ww1.microchip.com/downloads/en/Appnotes/MPLAB-Code-Configurator-CAN2.0B-Module-For-PIC18-00002714A.pdff
Please upload tutorials on USART.
SPI protocol class plz
Thanks for video,
Is the speed of I2C bus is depends on the VDD?
Thank you sir
I am trying to send a data from the PC using the uart save it in memory and then read from the memory and write again using the uart to display it on the pc. I have used several codes and the problem persists. I send an "a" or "01100001" and receive two bytes "00000000 00111111". Any idea what it could be? I used your code
Kindly visit support.microchip.com for assistance. Thank you.
I tried mcc (code configurator) simple master and eeprom example. Both worked but eeprom example is much better. It is a while (blocked) triggered but accomplised to made self state machine non blocking style.
Hi,
Why is msb bit sent first in the data byte?
Kindly address your question to support.microchip.com. Thank you.
Could you please provide the demo code?
Kindly visit support.microchip.com for assistance. We do not provide support on TH-cam. Thank you.
@@MicrochipTechnology youtube wont find out, just give him the code bro
MUITO BOM, MAS GOSTARIA DE VER UMA APLICAÇÃO COM ADS1110 (TEXAS) E O PIC 16F873A OU 870
Hi there, thank you for your feedback! We appreciate it and will pass it along to our product team. They will take it into consideration as they strive to enhance our code examples and software libraries.
can a slave control clock line ??
No i2c master is the source of clk signal. This is the syncron wave. Master need to shift out or in the 8bit data.
Tks for the presentation
Pongan subtitulos !!!!!!
NBA Jam T.E.Sega Genesis
Really great presentation, thank you.
Thank you!
@@MicrochipTechnology
That woman telephone operator at bangalore is totally unprofessional & doesn't know how to deal with people. I had called on 08030904444 regarding some queries but she totally behaved in an uncivilized manner. It will be better if there is some professional person instead of her