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.
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.