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

  Рет қаралды 28,960

Binder Tronics

Binder Tronics

Күн бұрын

Пікірлер: 52
@BinderTronics
@BinderTronics 4 жыл бұрын
Full playlist on the PIC microcontroller Programming kzbin.info/www/bejne/gYSsZ5mwhLWJsJI 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 жыл бұрын
@@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 жыл бұрын
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 жыл бұрын
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).
@erictutkowski849
@erictutkowski849 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 kzbin.info/www/bejne/r3fZe4uulr5nhZI
@stewartmclaughlin1199
@stewartmclaughlin1199 4 жыл бұрын
@@BinderTronics Wonderlik, baie dankie!
@adrianV68
@adrianV68 6 жыл бұрын
Would it change the procedure a lot if we wanted to establish communication with a bluetooth module?
@BinderTronics
@BinderTronics 6 жыл бұрын
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
@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 жыл бұрын
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.
@AlbertRei3424
@AlbertRei3424 3 жыл бұрын
How did you connect the PIC to the PC ? ¨Pickit3 ? It supports UART?
@BinderTronics
@BinderTronics 3 жыл бұрын
Watch the Schematic section again. I use a FTDI usb to serial.
@jasmenelee
@jasmenelee 2 жыл бұрын
Can u please make video on PIC18F27K42 on UART asynchronous receiver?
@BinderTronics
@BinderTronics 2 жыл бұрын
What is unclear in the datasheet?
@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 жыл бұрын
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
@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.
@gokulg9541
@gokulg9541 4 жыл бұрын
Well explained!
@prasanthchigurupatii
@prasanthchigurupatii 2 жыл бұрын
Loved
@diyelectronics3158
@diyelectronics3158 5 жыл бұрын
Header file error occurs usually. .why
@BinderTronics
@BinderTronics 5 жыл бұрын
#include for newer compilers. Otherwise going to need more context.
@diyelectronics3158
@diyelectronics3158 5 жыл бұрын
@@BinderTronics how can I add header files as we do in arduino. ..any link. .??
@BinderTronics
@BinderTronics 5 жыл бұрын
@@diyelectronics3158 Project Tree > right click > Add Existing Item kzbin.info/www/bejne/hYKZmY2woNuLg9k 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. kzbin.info/www/bejne/oJqnhpycl912bLc
@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
@pengpleb
@pengpleb 5 жыл бұрын
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 ( kzbin.info/www/bejne/g5qzqYmjn8Shfqs ) 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
@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 жыл бұрын
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.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
PROTOCOLS: UART - I2C - SPI - Serial communications #001
11:58
Electronoobs
Рет қаралды 1,4 МЛН
Programming the PIC16F84A in C with MPLAB X
14:19
James Smith
Рет қаралды 58 М.
Interrupts 🔴 PIC Microcontroller Programming Tutorial #5 MPLAB in C
10:11
Understanding UART
6:11
Rohde Schwarz
Рет қаралды 206 М.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН