Serial RS232 not working properly?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
kg300
Posts: 31
Joined: Thu May 31, 2018 6:25 am
Has thanked: 5 times
Been thanked: 1 time
Contact:

Serial RS232 not working properly?

Post by kg300 »

HI, I have a MikroC code based on ATMEGA32 to send and receive data from Labview GUI. with the use of Proteus and Virtual Comport it simulate nicelly, now i want to do it with FLOWCODE and PIC16F877A, I arrange flowcode with my little knowledge about RS232 but it not work correct. data send to labview display wrong value. can anyone point out the problem in my flowcode program...?

#include <built_in.h>
char DIG_Input,Read[2]; //declear variables
unsigned int adc_rd0,adc_rd1,adc_rd2,adc_rd3,adc_rd4,adc_rd5,adc_rd6,adc_rd7 ;
char adc_rd0c[6],adc_rd1c[6],adc_rd2c[6],adc_rd3c[6],adc_rd4c[6],adc_rd5c[6],adc_rd6c[6],adc_rd7c[6] ;
CHECk_PORT_B(); //function to get portB value
CHECk_PORT_A(); // function to get PortA value
send(); // function to sen sensor value to labview
void main() {
//////////////////////////////INITIALIZE///////////////////////////////////
DDRB=0x00 ;
DDRC=0xFF ;
PORTC=0x00;
UART1_Init(9600); // inital hardware UART and at 9600 bps
Delay_ms(100);
UART1_Write(10); // Send random value at beginning
while(1){
////////////////////////////Acquire_Data/////////////////////////////////
CHECk_PORT_B();
CHECK_PORT_A();
////////////////////////////Recive_Data///////////////////////////////
if(UART1_Data_Ready() == 1 ){ //if data in receive buffer is read?
Uart1_Read_text(Read,"EN",10); // read characters until delimiters sequences detected
PORTC=Read[0];
////////////////////////////Send_Data/////////////////////////////////
send();
}
}
}

CHECk_PORT_B(){
DIG_Input=PINB;
}

CHECK_PORT_A(){
adc_rd0 = ADC_Read(0);
Wordtostr(adc_rd0,adc_rd0c); // word to string convert
adc_rd1 = ADC_Read(1);
Wordtostr(adc_rd1,adc_rd1c);
adc_rd2 = ADC_Read(2);
Wordtostr(adc_rd2,adc_rd2c);
adc_rd3 = ADC_Read(3);
Wordtostr(adc_rd3,adc_rd3c);
adc_rd4 = ADC_Read(4);
Wordtostr(adc_rd4,adc_rd4c);
adc_rd5 = ADC_Read(5);
Wordtostr(adc_rd5,adc_rd5c);
adc_rd6 = ADC_Read(6);
Wordtostr(adc_rd6,adc_rd6c);
adc_rd7 = ADC_Read(7);
Wordtostr(adc_rd7,adc_rd7c);
}

send(){
if (UART1_Tx_Idle() == 1) { //if transmit shift register is empty ??
Uart1_write_text(adc_rd0c); // send 8 analogue values
Uart1_write_text(adc_rd1c);
Uart1_write_text(adc_rd2c);
Uart1_write_text(adc_rd3c);
Uart1_write_text(adc_rd4c);
Uart1_write_text(adc_rd5c);
Uart1_write_text(adc_rd6c);
Uart1_write_text(adc_rd7c);
Uart1_write(DIG_Input); //send 8 digital values
Uart1_write(10); // send serial termination character to end data
}
}
Attachments
16f877 Labview.rar
(457.28 KiB) Downloaded 216 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Serial RS232 not working properly?

Post by Benj »

Hello,

What version of Flowcode are you using?

Have you done a 1 second flasher test to confirm your configuration is all ok.
https://www.matrixtsl.com/wiki/index.ph ... ED_flasher

Post Reply