![]() | ![]() | ![]() |
| |||||||
| General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion? |
![]() |
| | Tools |
| | #1 |
|
I had a problem about transmitting first byte via UART... Where does it going? Simple UART between two 18f6722 or any other, but first byte always missing, and I receive zero. Is that problem in me, or simulation. I'm using C18, MPLAB 8.20, and Proteus 7.2? Please give me some idea. Here is some code and graphics... ------------------------------------------------------------ Fist PIC: ------------------------------------------------------------ #include <p18f6722.h> #include <usart.h> #include <string.h> #include "Variables.h" //char chT[8]; //char chR[10]; char ch; //------------------------------------------------------------------------- void Delay1ms(void){ // 1 milisekunda = 5000 taktova Delay1KTCYx(5); } //------------------------------------------------------------------------- void Delay_m(int count){ // kasnjenje u milisek. int i; for(i=0;i<count;i++) Delay1ms(); } //------------------------------------------------------------------------- void main() { char ii= 'A'; Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 129); Delay_m(20); while (1) { ch= ii++; if (ii > ('A'+25)) ii= 'A'; while (Busy1USART()); Write1USART(ch); } } ---------------------------------------------------------------------- Second PIC: --------------------------------------------------- #include <p18f6722.h> #include <usart.h> char ch; void main() { Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 129); // na GSM modul //TRISCbits.TRISC0=0; //RDS //TRISCbits.TRISC1=1; //CTS //PORTCbits.RC0=1; // Ready To Send signal za modem while (1) { while (!DataRdy1USART()); ch= Read1USART(); } } ------------------------------------------------ Sorry for comments. Link to download files: http://elvedinhamzagic.diinoweb.com/files/Public/UART_problem.rar I'm using these simple procedures from C18, and it should be fine. Processor is running at 20 MHz, baud rate is about 9600, everything is fine, interrupts are switched from code, but they also works. Everything except first byte!??? On graphic, first byte is zero, second 'B', and third 'C', counting from LSB up to eight bytes, starting from logical '10' (first is start/stop bit, second is not used, and last is also '0', TX9 i think) on every buffer sequence. For example, 1 0 0100001 0 1 0 1100001 0 1 are 1 0 'A' 0 1 0 'B' 0 1. | |
| |
| | #2 |
|
Try the transmitter with two stop bits, and the receiver with one.
| |
| |
| | #3 |
|
Thank you for your reply. Problem is in Michrochip USART library function for opening USART. Bitmask USART_ADDEN_ON should set ADDON bit in RCREG, but it sets SENDB bit in TXREG. SENDB bit is response for sending first byte of data as BREAK CHARACTER SEQUENCE, ignoring byte in TXREG as dummy or initiating. There should be USART_ADDEN_OFF used at openning USART port. In Mochrochip documentation that bitmask is not even mentioned, maybe it is added in new version (MCCv3.20) and not documented. Anyway, pretty bad work. Thanks again, i hope that it will be helpfull for someone who reads. I lost my week resolving such a mistake. | |
| |
|
| Tags |
| byte, problemwhere, uart |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| 512 byte arrays - C18? | futz | Micro Controllers | 8 | 23rd April 2008 03:47 PM |
| 8051 Serial UART Problem | ahmedragia21 | 8051/8951 | 6 | 16th December 2007 12:27 AM |
| Problem in applying configuration data to UART | tkvenki | Micro Controllers | 0 | 22nd March 2007 11:59 AM |
| PIC 16F628A UART Coding Problem | Gayan Soyza | Micro Controllers | 11 | 1st February 2007 12:59 PM |
| I²C Send Byte problem with PIC | hantto | Micro Controllers | 20 | 24th May 2005 01:53 PM |