Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

UART problem-Where is first byte?

Status
Not open for further replies.

Elvedin

New Member
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: **broken link removed**

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.
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top