Serial UART 🔴 PIC Microcontroller Programming Tutorial #7 MPLAB in C

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

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

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

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

      as I know, Input TRIS.. =1, output TRIS... = 0.
      TRISCbits.RC6 and RC7 are TX and RX.
      RC6 is transferred, RC7 receives mean RC6 output and RC7 input.
      Why you use both of them for input " RC6 RC7 = 1 "

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

      @@vantoanle8257 0:40

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

      @@BinderTronics thank you so much, i dont see that.But when reading PIC16F887 datasheet, I realized it doesn't have that line, so with pic16f887 I also configure it like you?

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

      @@vantoanle8257 12.1.1.1 Note 1. No need to alter the TRIS register.

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

    On a PIC18F45k22 I also had to set ANSELCbits.ANSC7 = 0 and ANSELCbits.ANSC6 = 0 . And be careful at the register names because you have two UARTS (TXSTA1 or TXSTA2, for example).
    In case someone needs this, ofc, not Binder Tronics.
    Thank you, it's working!

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

    I have a suggestion/request: Uart communication with the CRC peripheral. I'm using a PIC18F26Q10 to control stepper motors through TMC2209 where the more advanced features can be accessed through serial communication with CRC. Its not the only chip (tends to be high power/noisy chips) that wants or has this additional check. They have an example in the datasheet using code, but a lot of the PIC18F have CRC hardware built in. Ben Eater did a fantastic tutorial on how CRC works ("How do CRCs work?") but an example 'irl' would be awesome (for me at least). Great tutorial set, more on any peripheral would be great. How about USB or the new ADC2? Subscribed

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

      If noise is a issue use a RS232 to RS422 connection and keep the RS232 lines a short as possible. This eliminates 99% of the noise problem but this not always piratical. The industry approach to CRC is get someones open souce library for what ever protocol you are working with since most of it is standardized or someone in the company has already written one. I will have a look into it though. I am currently working on a CDC USB device video but I have no idea how long it will take. I will put ADC2 on the list. I am prioritizing getting SPI out the door at the moment.

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

      @@BinderTronics Good suggestion to eliminate noise. In my case the hardware I'm using doesn't give you another choice except uart with CRC bits. Ordinarily I'd be happy to get a C library, and do it in firmware but it seems a shame when it's a built in peripheral. I'll give the MPLAB Code Configurator a go and hopefully pick it apart.
      A USB serial is a great idea as is SPI, I think a lot more people will find it useful. Capacitive touch / mTouch / touch buttons might be another video with wider appeal (and fairly easy too).

  • @pengpleb
    @pengpleb 5 ปีที่แล้ว +3

    Thank you so much, finally got this damn UART to work. However, I had to do some changes under MPLAB X IDE v5.30 and XC8 v2.10:
    - #include
    - void __interrupt() high_isr(void);
    - void __interrupt(low_priority) low_isr(void);
    (Same signature when implementing the interrupts at the end of the file).

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

      Thanx for the update. Probably too get the compiler stander with other multi interrupt PICs.
      Added a comment on Tutorial #5 - Interrupts ( th-cam.com/video/MiPxVmj_nHI/w-d-xo.html ) if you want to claim credit.

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

      @@BinderTronics I think it is no longer necessary to include : #include

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

      @paul The header is there for reference. The compiler will drop is if it is included somewhere else.

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

      @@BinderTronics I have never included the header and I have no issue for now

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

    Well explained!

  • @prasanthchigurupatii
    @prasanthchigurupatii 2 ปีที่แล้ว +1

    Loved

  • @erictutkowski849
    @erictutkowski849 4 ปีที่แล้ว +3

    Really great channel! I've been giving your videos a watch and they help out so much. I'm trying to get UART working but I need some sort of display or terminal for it to send the transmission to and I'm not sure how to do that :/. Got any tips for setting up putty with it?

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

      Going to assume you got a CH340 or FTDI usb-to-serial board. Don't get a prolific based one... piece of crap. Otherwise follow this guide pbxbook.com/voip/sputty.html there are linux and mac guides there as well.

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

      @@BinderTronics not sure if I'm using what you stated above, But as for the chip it's a bit more complex I believe. I've been using a p32mx795f512l and while the ports are different from yours in many ways, your videos have been a great reference to use alongside the manual. I'll definitely check out the link for setting up putty though, thanks so much!

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

      @@BinderTronics Ok! I think I have the terminal working correctly now. Just have to fix up my code and make it run :)

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

      @@BinderTronics Finally got code working!
      For some reason my Serial to USB drivers weren't installed, which caused the brunt of my issues. Thanks a million for the putty set up though :)

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

    Mooi so! Weet jy hoe om groter datatipes soos float oor die lyne te stuur?

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

      Het 'n stuck kode wat dit doen in die video th-cam.com/video/yFvJXxaY4O0/w-d-xo.html

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

      @@BinderTronics Wonderlik, baie dankie!

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

    Can u please make video on PIC18F27K42 on UART asynchronous receiver?

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

      What is unclear in the datasheet?

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

    How did you connect the PIC to the PC ? ¨Pickit3 ? It supports UART?

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

      Watch the Schematic section again. I use a FTDI usb to serial.

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

    hello, I'm quite new to micro controller. I cant understand the start bit and the end bit of a signal. Could you please make it a bit clear. love your videos & thanks in advance.

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

      Frame format:
      Idle | start | data | parity | stop
      idle: digital high
      start : 1 bit width low
      data: 5-9 data bits.
      parity: 1 or 0 of 1 bit width
      stop : 1 or 2 high bit widths
      1 bit width is the baud rate. Since this is a Asynchronous hardware protocol, each bit has a set time it can be high or low. This also means that the sending and receiving end needs to be configured identical for it to work. So a start bit is 1 bit width low. The stop bits are 1 or 2 bit widths at the end of a frame.
      In most cases for UART you don't need to concern yourself with the how the frame is generated. All you need to do is load the transmit register (TXREG in this case) and the frame is generated for you. All you need to concern yourself with is the data width, parity type, number of stop bits and the baud rate in the setup.
      ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf
      19.4 Frame Formats

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

      Thanks a lot

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

    How will you receive from the UART2? RCREG2?! . Why did you use the RCREG instead of RCREG1 for UART1?

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

      Going to assume your PIC microcontroller has 2 or more UART module on it. I use RCREG cause that is the naming of the C structure for that register on the PIC microcontroller I am using. Since there is only one UART on the PIC it does not need the number at the end of the naming. In the case where there is more than one module that have the same register structure (doing the same thing) the naming will be registerX (UARTx). So if you are working with UART1. All register associated with UART1 will be followed by a 1 thus the RCREG1 in your case.

  • @adrianV68
    @adrianV68 6 ปีที่แล้ว

    Would it change the procedure a lot if we wanted to establish communication with a bluetooth module?

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

      No, just need to change the baud to match the module and create a fifo buffer for the received data. Also may need to create some form of AT parser. You will probably run into lack memory on the 18f4520 before anything else. If you are using another PIC I would suggest using Microchip Code Configurator plug-in to setup the UART.

    • @adrianV68
      @adrianV68 6 ปีที่แล้ว

      Thanks

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

    hi sir, i want lora ra-02 module interface with pic microcontroller, so please help

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

      Only familiar with Lora RF1276-868RS232 witch is just straight RS232 interface. Have not touched the ra-02 modules.

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

    Header file error occurs usually. .why

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

      #include for newer compilers. Otherwise going to need more context.

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

      @@BinderTronics how can I add header files as we do in arduino. ..any link. .??

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

      @@diyelectronics3158 Project Tree > right click > Add Existing Item
      th-cam.com/video/OQ6hZzkvXMw/w-d-xo.html same place as adding new files

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

    SPBRGH = (gen_reg & 0xFF00) >> 8;
    SPBRG = gen_reg & 0x00FF;
    teacher why did you do this ?I did not understand. Is to ignore high byte

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

      SPBRGH and SPBRG are both 8 bits wide registers. gen_reg is 16 bits wide. SPBRGH is equal to the upper 8 bits of gen_reg. SPBRG is equal to the lower 8 bits of gen_reg.
      th-cam.com/video/jiDUifbxC6U/w-d-xo.html

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

      @@BinderTronics thank you so much. So my teacher, what do TXREG and RXREG do?

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

      TXREG = data to send. RXREG = data received. datasheet section 18.2.1 and 18.2.2

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

    I keep getting error conflicting data types for uart_send... any idea?

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

      uint8_t *data;
      uart_send(data);
      uint8_t data;
      uart_send(&data);

    • @shite9678
      @shite9678 2 ปีที่แล้ว +1

      Thanks for the response, I've got it all worked out now. Using the PIC18F45K22 like stated in comments below I have multiple registers ex. "TXSTA1" and I'm on C99 which has some syntax differences ex. Interrupts. I'm controlling basic GPIO functions through UART atm and now working on reading i2c Honeywell temp and humidity sensor. Thanks for all you do bud and look forward to more videos.