Komunikasi Serial Mikrokontroler Pic18f2520

Posted on  by admin
  1. Mikrokontroler Adalah

Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai basic komunikasi serial (UART) yang mana komunikasi ini sangat sering sekali diperlukan untuk mengakses berbagai macam device seperti komputer, modul wireless, kamera, komunikasi antar mikrokontroller, sms gateway dan lainnya, karena komunikasi ini sangatlah mudah dan sederhana sekali, maka komunikasi ini jadi sering digunakan oleh para engineer dalam menyelesaikan masalah yang berkaitan dengan komunikasi ke device lain. Pada contoh ini saya akan memberikan cara bagaimana caranya untuk mengirikan data berupa karakter ke komputer dan juga data berupa nilai integer, device yang diperlukan untuk komunikasi ini yaitu RS232 yang mana terdapat IC MAX232, fungsi dari device ini yaitu untuk menyamakan level tegangan antara device mikrokontroller dengan device yang dituju, misal komputer, jika level tegangan sudah sama yaitu TTL maka komunikasi bisa dilakukan dengan lancar, berikut gambar skema dan programnya. Cara menggunakan alat ini yaitu pertama aktifkan mikrokontroller kemudian pasang rangkaian RS232 ke mikrokontroller, setelah terpasang, hubungkan ke port serial komputer jika menggunakan PC atau jika ingin menggunakan USB dapat menggunakan konverter Serial to USB, setelah itu install driver kabel Serial to USB tersebut, jika sudah selesai, buka software 'Hyperterminal' kemudian buka port com yang digunakan, setelah itu pilih baudrate 9600, klik konek maka device komputer dengan mikrokontroller akan terhubung.

It is difficult to help as there is no indication what you have tried so far. Keep in mind that an embedded processor, in general, comes with no built in operating system. The printf method on even a small Linux computer like an ARM based RaspberryPi invokes 100s if not 1000s of lines of code that are part of the operating system.

Ada beberapa komunikasi data serial dari mikrokontroler, mulai dari komunikasi point to point menggunakan RS232 dalam satu frame protocol. Komunikasi data dilakukan dengan pengiriman beberapa karakter ASCII dari PC ke mikrokontroler dan kembali ke PC. Adapun aplikasi yang digunakan PC untuk menerima karakter ASCII tersebut adalah hyperterminal. Tapi bila peralatan seperti modem, ponsel, bluetooth, data logging, barcode menggunakan komunikasi serial, mengapa ditancapkan pada port usb? Bukan pada port serial. Disini saya menggunakan 2 mikrokontroler AVR ATmega 32. Dengan kristal 8 Mhz, seharus'y yg bagus utk komunikasi serial menggunakan kristal 11.059200 Mhz, supaya baudrate error'y 0.0%. Sensor ultrasonik yang saya gunakan HC-SR04 (sensor cina coy!), servo yang saya pakai micro gws, dan baterai yang saya gunakan adalah baterai lipo 2S 500mAh.

Mikrokontroler adalahAdalah

In general, on an embedded processor, like a PIC, you need to write all that code if you truly want to abstract to the level of single method call such as printf. In general, on an embedded processor, like a PIC, you need to first setup the physical interface. If you are using the UART device you may need to setup the BAUD rate and the Parity just to name 2 features.

You may want to setup interrupts to better handle high speed transfers. Or you may try to handle everything in your code for simplicity sake. Most people do arrive at a solution where 1 function call is all that is needed to send data out a PIC serial port. But it is very unlikely they will try to emulate a printf type of method. The reason being it is difficult to implement a method that can accept an arbitrary number of arbitrary types.

Mikrokontroler Adalah

I think you need to use something called a 'Template Processor'. Way beyond this discussion.

St2000 I think the assumption was that your setup was not working and the results would be the same even after you changed the code. Hence the reason for using an oscilloscope along with the code change. We need to step back and see if your code and hardware were working at a more fundamental level. If you didn't look at the output with an oscilloscope then it would be difficult to make any progress. Quoted for emphasis.

Komunikasi

Fl studio free download demo. You need to get some SIMPLER code working, which sends just one character, before you try to do something more complicated. You keep saying 'I have checked baud rate', but don't mention what you actually checked. Something fundamental is wrong, so you need to fix that first. As a matter of interest, what terminal program are you using on your PC to monitor the serial port? What you describe is a Baud Rate mismatch. How are you checking the Baud rate (As ric has asked several times in previous posts)? The best way is to send 0x55 (ASCII 'U') and measure the bit time on an O'scope.

Sending a 7 RCIE = 1; // receive interrupt enable GIE = 1; // global interrupt enable PEIE = 1; // Peripheral Interrupt Enable bit Why are you enabling interrupts when you do not have an ISR? Did you step through this code in the MPLAB Simulator to ensure all registers are actually being properly setup? And that the code is running the way you want? And how to check output with oscilloscope.

I mean it will gives oly square pulse right? Not any character. Thank you for using an oscilloscope.

An RS232 signal contains characters that are padded with start, stop, and even parity bits. These extra bits depend on how you set things up. But the majority of bits will be the character you are sending.

If you send 0x55 or 0xaa as suggested above you will be sending 0b01010101 or 0b10101010 respectively. This will look like a short burst of a square wave. Sure, there will be other bits at the beginning and end that will not line up. But the signal will (mostly) look like a square wave.

You will have to become familiar with your oscilloscope. Enough so you can capture the short burs of this square wave. I will leave that up to you for now. You can continue sending the same character over and over again in a program loop. This will make it easier to see the square wave on the oscilloscope. Easier to verify that the width of 1 bit is correct for the baud rate you are expecting.