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 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?
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!
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
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.
@@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).
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).
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.
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?
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.
@@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!
@@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 :)
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.
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
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.
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.
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
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.
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.
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 "
@@vantoanle8257 0:40
@@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?
@@vantoanle8257 12.1.1.1 Note 1. No need to alter the TRIS register.
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!
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
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.
@@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).
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).
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.
@@BinderTronics I think it is no longer necessary to include : #include
@paul The header is there for reference. The compiler will drop is if it is included somewhere else.
@@BinderTronics I have never included the header and I have no issue for now
Well explained!
Loved
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?
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.
@@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!
@@BinderTronics Ok! I think I have the terminal working correctly now. Just have to fix up my code and make it run :)
@@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 :)
Mooi so! Weet jy hoe om groter datatipes soos float oor die lyne te stuur?
Het 'n stuck kode wat dit doen in die video th-cam.com/video/yFvJXxaY4O0/w-d-xo.html
@@BinderTronics Wonderlik, baie dankie!
Can u please make video on PIC18F27K42 on UART asynchronous receiver?
What is unclear in the datasheet?
How did you connect the PIC to the PC ? ¨Pickit3 ? It supports UART?
Watch the Schematic section again. I use a FTDI usb to serial.
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.
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
Thanks a lot
How will you receive from the UART2? RCREG2?! . Why did you use the RCREG instead of RCREG1 for UART1?
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.
Would it change the procedure a lot if we wanted to establish communication with a bluetooth module?
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.
Thanks
hi sir, i want lora ra-02 module interface with pic microcontroller, so please help
Only familiar with Lora RF1276-868RS232 witch is just straight RS232 interface. Have not touched the ra-02 modules.
Header file error occurs usually. .why
#include for newer compilers. Otherwise going to need more context.
@@BinderTronics how can I add header files as we do in arduino. ..any link. .??
@@diyelectronics3158 Project Tree > right click > Add Existing Item
th-cam.com/video/OQ6hZzkvXMw/w-d-xo.html same place as adding new files
SPBRGH = (gen_reg & 0xFF00) >> 8;
SPBRG = gen_reg & 0x00FF;
teacher why did you do this ?I did not understand. Is to ignore high byte
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
@@BinderTronics thank you so much. So my teacher, what do TXREG and RXREG do?
TXREG = data to send. RXREG = data received. datasheet section 18.2.1 and 18.2.2
I keep getting error conflicting data types for uart_send... any idea?
uint8_t *data;
uart_send(data);
uint8_t data;
uart_send(&data);
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.