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

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024

Комментарии • 39

  • @BinderTronics
    @BinderTronics  4 года назад

    Full playlist on the PIC microcontroller Programming ruclips.net/video/KSI6fzOPVz0/видео.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

  • @patrick_cpp
    @patrick_cpp 3 года назад +1

    Danke, endlichen funktioniert es 👍

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

  • @keydarkman
    @keydarkman 5 лет назад +4

    Very good man, good tutorial.

  • @marcosdotadelima8571
    @marcosdotadelima8571 3 года назад +1

    amazing, it worked perfectly

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

  • @leventdemirci8328
    @leventdemirci8328 3 года назад +1

    you are good man thak you for tutorial

  • @valeryngwa
    @valeryngwa 5 лет назад +1

    very interesting. good tutorial

  • @ewenjugault8917
    @ewenjugault8917 4 года назад +1

    nice tutorial

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

  • @alikhorami7605
    @alikhorami7605 2 года назад

    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  2 года назад

      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  2 года назад

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

  • @cralx2k
    @cralx2k 4 года назад +1

    Thank you so much.

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

  • @Tortuga2321
    @Tortuga2321 4 года назад

    which ide do you use, teacher

    • @BinderTronics
      @BinderTronics  4 года назад

      MPLAB X IDE with the XC8 compiler. Install guide ruclips.net/p/PLtuqBdbsL-DtSo1a9pS4sLkoaU3Or2pl3

    • @Tortuga2321
      @Tortuga2321 4 года назад

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