I2C and RTC DS1307 🔴 PIC Microcontroller Programming Tutorial #11 MPLAB in C

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ต.ค. 2024

ความคิดเห็น • 39

  • @BinderTronics
    @BinderTronics  4 ปีที่แล้ว

    Full playlist on the PIC microcontroller Programming th-cam.com/video/KSI6fzOPVz0/w-d-xo.html
    If there is anything you would like to see let me know.

    • @dpgregory
      @dpgregory 4 ปีที่แล้ว

      I2C Slave would be very helpful, not sure how much demand there would be for it though

    • @som3oneMw
      @som3oneMw 3 ปีที่แล้ว

      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

    • @kianstrydom4380
      @kianstrydom4380 3 ปีที่แล้ว

      Same tutorial but in Assembler

    • @BinderTronics
      @BinderTronics  3 ปีที่แล้ว

      @@kianstrydom4380 When I feel like pulling my teeth

  • @keydarkman
    @keydarkman 5 ปีที่แล้ว +4

    Very good man, good tutorial.

  • @parthbaraiya13
    @parthbaraiya13 5 ปีที่แล้ว +2

    Really very good Video, actually every video is great. Please keep it up make more videos. Thank you

    • @BinderTronics
      @BinderTronics  5 ปีที่แล้ว

      Thanks. Always great to get some feedback

  • @marcosdotadelima8571
    @marcosdotadelima8571 3 ปีที่แล้ว +1

    amazing, it worked perfectly

  • @leventdemirci8328
    @leventdemirci8328 3 ปีที่แล้ว +1

    you are good man thak you for tutorial

  • @ewenjugault8917
    @ewenjugault8917 4 ปีที่แล้ว +1

    nice tutorial

  • @cralx2k
    @cralx2k 4 ปีที่แล้ว +1

    Thank you so much.

  • @valeryngwa
    @valeryngwa 5 ปีที่แล้ว +1

    very interesting. good tutorial

  • @alikhorami7605
    @alikhorami7605 ปีที่แล้ว

    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

    • @BinderTronics
      @BinderTronics  ปีที่แล้ว

      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.

    • @BinderTronics
      @BinderTronics  ปีที่แล้ว

      This is your issue.
      SSPCON2bits.ACKDT = ack;
      SSPCON2bits.ACKEN = 1;
      Watch the video again or read the datasheet.

  • @naylinaungaung8992
    @naylinaungaung8992 3 ปีที่แล้ว

    Don't understand the meaning of
    uint8_t YearL:4;
    uint8_t YearH:4;
    .
    .
    .
    etc.
    Could u explain? thz u

    • @BinderTronics
      @BinderTronics  3 ปีที่แล้ว

      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

  • @ユンユン-b8y
    @ユンユン-b8y 3 ปีที่แล้ว

    I really appreciate you! can you make 1 video about i2c communication between 2 pic 18f4520. that will help me a lot

    • @BinderTronics
      @BinderTronics  3 ปีที่แล้ว

      Mind telling me why you want to use I2C? You will have a much easier time using UART or SPI.

  • @patrick_cpp
    @patrick_cpp 3 ปีที่แล้ว +1

    Danke, endlichen funktioniert es 👍

  • @user-su5sq5ib3i
    @user-su5sq5ib3i 2 ปีที่แล้ว +1

    You are a great coder

    • @BinderTronics
      @BinderTronics  2 ปีที่แล้ว

      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.

  • @parthbaraiya13
    @parthbaraiya13 5 ปีที่แล้ว

    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?

    • @BinderTronics
      @BinderTronics  5 ปีที่แล้ว +1

      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

    • @BinderTronics
      @BinderTronics  5 ปีที่แล้ว +1

      You might also need to port between C and C++, depending on your needs regarding the pn532.

    • @parthbaraiya13
      @parthbaraiya13 5 ปีที่แล้ว

      @@BinderTronics Thank you

  • @robinight
    @robinight 5 ปีที่แล้ว

    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
      @BinderTronics  5 ปีที่แล้ว +1

      Look at section 32.6.6.4 of the datasheet. Do you have the correct pull-up resistors on the interface lines?

    • @robinight
      @robinight 5 ปีที่แล้ว

      @@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.

    • @BinderTronics
      @BinderTronics  5 ปีที่แล้ว +1

      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
      @BinderTronics  5 ปีที่แล้ว +1

      @@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

    • @robinight
      @robinight 5 ปีที่แล้ว

      @@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

  • @Tortuga2321
    @Tortuga2321 4 ปีที่แล้ว

    which ide do you use, teacher

    • @BinderTronics
      @BinderTronics  4 ปีที่แล้ว

      MPLAB X IDE with the XC8 compiler. Install guide th-cam.com/play/PLtuqBdbsL-DtSo1a9pS4sLkoaU3Or2pl3.html

    • @Tortuga2321
      @Tortuga2321 4 ปีที่แล้ว

      @@BinderTronics thank you. I saw it later. Sorry