Hi,
Now I am establish a UART serial communication between two PIC18F57K42 microcontroller and then personal computer. The mentioned microcontroller have two UART modules.
MCU1_Tx2(transmit) -----------> MCU2_RX2 (receive) & MCU2_TX2 (transmit) -------------> PC (receive)
The above mentioned flow is the sequence of my code.
I have done the above sequence in the way of single character transmit(MCU1) , receive(MCU2) again transmit(MCU2) and received by PC succesfully.
But I transmit string character from MCU1 to MCU2 , it's transmission & receive are okay. It is checked by using USB module with PC. After received by MCU2, inside the program i have stored in that string character by using a char buffer variable. Then I pushed the string variable to PC through MCU2 transmit pin. Here i got a trouble what the string conversion is making wrong, I think so. But I pushed single string line , i received correctly. but i push more than one , the string characters are collapsed and mismatched.
Here i attached my code, Please let me know what is going wrong.
Master code _ MCU1(transmission only)/////////////////////////////////////Master code _ MCU1(transmission only)/////////////////////////////////////
#include<xc.h>
#include<stdio.h>
#include<math.h>
//////////////////////////////////////UART2_transmission/////////////////////
void UART2_Write(uint8_t txData)
{
while(0 == PIR6bits.U2TXIF)
{
}
U2TXB = txData; .
}
////////////////////////////////////////UART2_string_transmission function///////////////////////////
void UART2_string(char *s)
{
while( *s)
{
UART2_Write(*s++);
}
}
////////////////////////////////////main function//////////////////////
void main(void)
{
Initialize(); /////here initialize oscillator and UART configuration
TRISCbits.TRISC0 = 0;
LATCbits.LATC0 = 1;
while (1)
{
UART2_string("UART_UART");
UART2_Write('\n');
UART2_string("MCU1_MCU2");
UART2_Write('\n');
UART2_string("MCU2_PC");
UART2_Write('\n');
}
}
The following is the MCU2 (slave for MCU1 & master for PC) code
/////////////////////////////////////MCU2(master and slave)/////////////////////////////////////
#include<xc.h>
#include<stdio.h>
#include<math.h>
char data_in; /////global variable for tx and rx
//////////////////////////////////////UART2_transmission/////////////////////
void UART2_Write(uint8_t txData)
{
while(0 == PIR6bits.U2TXIF)
{
}
U2TXB = txData; .
}
/////////////////////////uart2_receiver function///////////////////////////
uint8_t UART2_Read(void)
{
while(!PIR6bits.U2RXIF)
{
}
if(1 == U2ERRIRbits.FERIF)
{
U2CON1bits.ON = 0;
U2CON1bits.ON = 1;
}
return U2RXB;
}
////////////////////////////////////////UART2_string_transmission function///////////////////////////
void UART2_string(char *s)
{
while( *s)
{
UART2_Write(*s++);
}
}
////////////////////////////////////////Uart2_receiver__string conversion//////////////////////////
void UART2_ReadString(char *Output, unsigned int length)
{
int i;
for(int i=0;i<length;i++)
{
Output[i] = UART2_Read();
}
}
/////////////////////////////////////////////////main function///////////////////////////////////
void main(void)
{
Initialize(); /////here initialize oscillator and UART configuration
TRISCbits.TRISC0 = 0;
LATCbits.LATC0 = 1;
while (1)
{
UART2_ReadString(&data_in ,10); /////for received string conversion & storing the data in buffer ////actually 9 but i add 1 more for '\0' /////but trying 9 and 10 also
UART2_string(&data_in); /////transmitted to PC
UART2_ReadString(&data_in ,10); /////for received string conversion & storing the data in buffer ////actually 9 but i add 1 more for '\0' /////but trying 9 and 10 also
UART2_string(&data_in); /////transmitted to PC
UART2_ReadString(&data_in ,8); /////for received string conversion & storing the data in buffer ////actually 7 but i add 1 more for '\0' /////but trying 7 and 8 also
UART2_string(&data_in); /////transmitted to PC
}
}
Advance in thanks...