i second @dpgregory‘s request for slave program. i‘ve been trying to figure out how to setup a pic18f2550 as a slave, but a few things in the datasheet are unclear to me
Thank you but please don't take this as a example of good code. This will not fly in a production environment. It is written for beginners to understand.
i worked on I2C and i used RFID device PN532 of adafruit so do you think it is compatible with the PIC microcontroller? 2) do you think every component is compatible with every Microcontroller?
I see no reason for the pn532 chip to not too be compatible. The trick here is to port the Arduino code to PIC eg. the twi lib command changes (Arduino) like this to a start transmit (I2C = TWI) Arduino Wire.beginTransmission(device_addr); changes to -> PIC i2c_start(); i2c_write(device_addr); 2) No, there are many factor that influence compatibility between a device and Microcontrollers like operation speed, operating voltage and does the Microcontroller have a peripheral for it. There are ways to get around this, like bit-bang the protocol and using level snifters. An example of the is PIC Programming Tutorial #14 - Controlling A Servo, video where I had to clock down the cpu to get a PWM of 50Hz
Very good .... the best I2C tutorial I've seen. I have a 16f15376 pic and the datasheet is very similar to the one it presented. I followed it step by step, but couldn't make the SDA and SCL outputs generate the square waves they were supposed to. Could you take a look at my code? thanks
@@BinderTronics I looked at the sentence 32.6.6.4 it's very similar to that of your pic. I put pull up resistors, set the ports according to the datasheet. I wrote the functions just like you did. But for some failure, I can't see the changes in the pins configured to be SCL and SDA.
Got a GitHub link to your code? It is going to be a question if i get to it. Otherwise you can try electronics.stackexchange.com . Just a note on the resistors 2K2@100k 4k7@400k 10K@1M (not sure about the 10K@1M one). Also state the frequency the pic is operating at and the device you are trying to communicate with assuming it is a DS1307.
@@BinderTronics This link is the same as the one I sent. And I didn't find any answers in the forum. Can you confirm that you really attached it? I posted on Github too... github.com/Rmanzoli/Robson/commit/a43a34c6a412373de6412a2d70071ecef15d6914#diff-ad3a361136c219fcd0959a37db615db8
datatype name : bits datatype : in this case uint8_t so 8bits wide variable name : anything you want to call the veriable bits : the number of bits to use. In the case of yearX it splits a single uint8_t variable into two 4-bit wide variables. Example YearL = 2; YearH = 3; is the same as uint8_t Year = 0x32 You can search *struct bitfield* for more information
Full playlist on the PIC microcontroller Programming ruclips.net/video/KSI6fzOPVz0/видео.html
If there is anything you would like to see let me know.
I2C Slave would be very helpful, not sure how much demand there would be for it though
i second @dpgregory‘s request for slave program. i‘ve been trying to figure out how to setup a pic18f2550 as a slave, but a few things in the datasheet are unclear to me
Same tutorial but in Assembler
@@kianstrydom4380 When I feel like pulling my teeth
Danke, endlichen funktioniert es 👍
Kein Problem
Really very good Video, actually every video is great. Please keep it up make more videos. Thank you
Thanks. Always great to get some feedback
Very good man, good tutorial.
amazing, it worked perfectly
You are a great coder
Thank you but please don't take this as a example of good code. This will not fly in a production environment. It is written for beginners to understand.
i worked on I2C and i used RFID device PN532 of adafruit so do you think it is compatible with the PIC microcontroller?
2) do you think every component is compatible with every Microcontroller?
I see no reason for the pn532 chip to not too be compatible. The trick here is to port the Arduino code to PIC eg. the twi lib command changes (Arduino) like this to a start transmit (I2C = TWI)
Arduino
Wire.beginTransmission(device_addr);
changes to ->
PIC
i2c_start();
i2c_write(device_addr);
2) No, there are many factor that influence compatibility between a device and Microcontrollers like operation speed, operating voltage and does the Microcontroller have a peripheral for it. There are ways to get around this, like bit-bang the protocol and using level snifters. An example of the is PIC Programming Tutorial #14 - Controlling A Servo, video where I had to clock down the cpu to get a PWM of 50Hz
You might also need to port between C and C++, depending on your needs regarding the pn532.
@@BinderTronics Thank you
you are good man thak you for tutorial
very interesting. good tutorial
nice tutorial
Very good .... the best I2C tutorial I've seen.
I have a 16f15376 pic and the datasheet is very similar to the one it presented.
I followed it step by step, but couldn't make the SDA and SCL outputs generate the square waves they were supposed to.
Could you take a look at my code?
thanks
Look at section 32.6.6.4 of the datasheet. Do you have the correct pull-up resistors on the interface lines?
@@BinderTronics
I looked at the sentence 32.6.6.4 it's very similar to that of your pic.
I put pull up resistors, set the ports according to the datasheet. I wrote the functions just like you did.
But for some failure, I can't see the changes in the pins configured to be SCL and SDA.
Got a GitHub link to your code? It is going to be a question if i get to it. Otherwise you can try electronics.stackexchange.com . Just a note on the resistors 2K2@100k 4k7@400k 10K@1M (not sure about the 10K@1M one). Also state the frequency the pic is operating at and the device you are trying to communicate with assuming it is a DS1307.
@@robinight Removed your mail from the previews comment:
I posted the code on a microchip forum. The link is:
www.microchip.com/forums/m1115621.aspx
@@BinderTronics This link is the same as the one I sent. And I didn't find any answers in the forum. Can you confirm that you really attached it?
I posted on Github too...
github.com/Rmanzoli/Robson/commit/a43a34c6a412373de6412a2d70071ecef15d6914#diff-ad3a361136c219fcd0959a37db615db8
when i recv from slave i always get 0xFF
what is the problem??
unsigned char i2c_read(unsigned char ack)
{
unsigned char res;
i2c_wait_if_busy();
SSPCON2bits.RCEN = 1;
while (!SSPSTATbits.BF);
w8();
res = SSPBUF;
SSPCON2bits.ACKDT = ack;
SSPCON2bits.ACKEN = 1;
return res;
}
w8 function waits for SSPIF and clear it again
and wait if busy just waits if bus is busy
Looks like your slave device is not talking. You are going to have to put a scope on it and see what the data lines are doing.
This is your issue.
SSPCON2bits.ACKDT = ack;
SSPCON2bits.ACKEN = 1;
Watch the video again or read the datasheet.
Thank you so much.
Don't understand the meaning of
uint8_t YearL:4;
uint8_t YearH:4;
.
.
.
etc.
Could u explain? thz u
This only applies to the struct keyword.
Format
datatype name : bits
datatype : in this case uint8_t so 8bits wide variable
name : anything you want to call the veriable
bits : the number of bits to use.
In the case of yearX it splits a single uint8_t variable into two 4-bit wide variables.
Example
YearL = 2; YearH = 3; is the same as uint8_t Year = 0x32
You can search *struct bitfield* for more information
I really appreciate you! can you make 1 video about i2c communication between 2 pic 18f4520. that will help me a lot
Mind telling me why you want to use I2C? You will have a much easier time using UART or SPI.
which ide do you use, teacher
MPLAB X IDE with the XC8 compiler. Install guide ruclips.net/p/PLtuqBdbsL-DtSo1a9pS4sLkoaU3Or2pl3
@@BinderTronics thank you. I saw it later. Sorry