Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RS232 Transmission Sync

Status
Not open for further replies.

Zwilorg

Member level 5
Joined
Oct 13, 2010
Messages
89
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,906
Hello,

I am having some trouble getting a proper connection between the pic 16F877 and the computer.

I am simulating everything with isis proteus and getting the with the program RS232analyzer

**broken link removed**

Altough the data packages get out the information does not arrive properly at the 232analyzer :S

a little bit of the code:

Code:
#define	XTAL_FREQ	4MHZ
#include <stdio.h>
#include <htc.h>
#include <pic.h>
#include <math.h>
#include "lcd.h"
#include "usart.h"
#include <string.h>



void main(void)
{

	System_init();    			// Calling System_Init Subroutine
	INTCON=0;					// purpose of disabling the interrupts
	init_comms();				// set up the USART - settings defined in usart.h
	init_adc(); 				// Calling init_adc Subrotine
	lcd_init();					// Calling lcd_init defined in lcd.h
	lcd_goto(0);				// select first line in LCD
	lcd_puts("Encoder:");		// display text in first line
	lcd_goto(0x40);				// Select second line
	lcd_puts("Tempera: ");		// display text in second line
	
	Counter=0;					// Setting the step counter as 0
	temp=0;
while(1)
{
		lcd_goto(0x48);	// Select second line
		display_value(Counter);
		lcd_putch('C');
		lcd_goto(0x08);	
		display_value1(Counter);
		lcd_putch('m');
		__delay_ms(100);

	printf("\n%004d%%%04d\n", Counter,temp);

Counter=Counter+1;

}						// End of While(1)

}						// End of void(main)


the uart.h, determinations

Code:
#define BAUD 9600      
#define FOSC 4000000L
#define NINE 0     /* Use 9bit communication? FALSE=8bit */
#define 	SPEN 1;
#define 	CREN 1;	//Enable Receiver (RX)
#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED 1



i don´t know what is happening :S maybe it is a proplem on the sync?



Best regards,
Zwi
 

No one can help?

i believe it is all about the timing... maybe the baudrate? or the delay must be proper?...

please help :p
 

thanks for the input ;)

but if the virtual terminal is sending and receiving doesn´t that mean that the circuit is built properly?
 

You have defined a nine bit communication meaning you are sending parity. You have to manually compute your parity in software and ensure the analyzer parity is enabled. But i would that you use eight bit comm without parity by not defining "nine". Also check your baud setting and start bit.
 
I didn´t see in your program where is received and treated incomming serial data.
If you intend to use interruption the vector is not present at the above code.

+++
 
@samson A.

that is a nice idea never thought about that! will try it out ;) thank you

@andre_teprom

i am indeed not using interrupts at all, just sending the data everysingle time the while(1) gets to the end :s i never used interrupts, but i will check to see if that helps ;)

----

I don´t know why but i am trying now with the same program i used to take the screen and the fidelity of the data income as increase ALOT, check it out:

Code:
 Signal received: DSR Turned ON ...
Data received: <LF>0000%0000<LF>
Data received: <LF>0001%0000<LF>
Data received: <LF>0002%0000<LF>
Data received: <LF>0003%0000<LF>
Data received: <LF>
Data received: 0004%0000<LF>
Data received: <LF>0005
Data received: %0000<LF>
Data received: <LF>0006%0000
Data received: <LF>
Data received: <LF>0007%0000<LF>
Data received: <LF>0008%0000<LF>
Data received: <LF>0009%0000<LF>
Data received: <LF>0010%0000<LF>
Data received: <LF>0011%0000<LF>
Data received: <LF>0012%0000<LF>
Data received: <LF>0013%0000<LF>
Data received: <LF>0014%0000<LF>
Data received: <LF>001
Data received: 5%0000<LF>
Data received: <LF>0016%000
Data received: 0<LF>
Data received: <LF>0017%0000<LF>
Data received: <LF>0018%0000<LF>
Data received: <LF>0019%0000<LF>
Data received: <LF>0020%0000<LF>
Data received: <LF>0021%0000<LF>
Data received: <LF>0022%0000<LF>
Signal received: DSR Turned OFF ...

but i need it to not miss a single data package and to not take them apart like in the lines:
Data received: <LF>0016%000
Data received: 0<LF>

So i am going to try your ideas ;) thanks!

i will reply again with the results


P.S:

Is it hard to create a routine out of the while(1) in the void main that sends a string from 1sec from 1sec, instead of what i have? (what i have is that at each end of the while(1) it sends a string. Meaning that if the step motor is running at a very high speed the speed of the output data is very high, and if the speed is low the data output speed is low aswell)
 
Last edited:

but i need it to not miss a single data package and to not take them apart like in the lines:
Data received: <LF>0016%000
Data received: 0<LF>
Nothing is missing here. The problem is just in your way of receiving the data, ignoring any delimiters.
 
@FvM

i used to have delimiters yes with the break from enter "/n" but the problem persisted so i took it out because i thought it was a problem on the sync :S
 

Let me introduce a concept that may help you.
That´s TIME SLICE.

In order to take your program more robust is desirable separate some tasks ( LCD / Serial ) wich may conflict.
I can sugest the following skeleton :
Code:
if ( TimeSlot >= 3 ) TimeSlot = 0 ;
switch ( TimeSlot++ )
{
case 0 : LCD_routines() ; break ;
case 1 : Serial_routines() ; break ;
case 2 : Other_routines() ; break ;
}

I could not identify in your code if tokening all that funcions where really the problem cause, but at least, this way will be easy to you debug separatelly each function ( applying comment statement - // - to disable running some funcion to check it impact over other funcions ).

+++
 
@andre_teprom

i am going to do that :p you are right it makes it alot easier... i was using breaking points to test the program ;)


-----


i am having another doubt hmmm maybe someone can help me

i am now trying to gather all the bytes arriving to the PIC (untill the break '/0') from the pc to create an array

on main.c

Code:
char *Receive_MSG(char *String, unsigned short int MSG_Length)
{						
	unsigned short int Index = 0;	// Message Index
	
	while(Index < MSG_Length)
	{	
		String[Index] = getch();
		if(String[Index] != 13 && String[Index] != 10)
		{
			String[Index + 1] = '\0';		// Set the next character to NULL
			Index++;
		}
		else
		{
			String[Index + 1] = '\0';		// Set the next character to NULL
			break;
		}
	}
	return String;
}

void main(void)
{


	while(1){
if(RCIF)
{
		input = getch();	// read a response from the user
		printf("\rI detected [%c]",input);	// echo it back
}

		lcd_goto(0x48);	// Select second line
		display_value1(value_dec);
		lcd_putch('C');
		lcd_goto(0x08);	
		display_value1(input);
		lcd_putch('m');
		__delay_ms(100);


value_dec=input-0x30;
}


the "value_dec=input-0x30;" it to convert every single byte from ascii to dec (from 0 to 9 if i am not mistaken) i will later get this part of the code on the subroutine to convert every byte incoming and join them after to create the array.


This is just not working! i took the routine Receive_MSG from somewhere in this forum some time ago :S


Error [984] C:\Users\Zwi\Desktop\mplab 232 teste\main.c; 44.1 type redeclared
Error [1098] C:\Users\Zwi\Desktop\mplab 232 teste\main.c; 44.1 conflicting declarations for variable "Receive_MSG" (C:\Users\Zwi\Desktop\mplab 232 teste\usart.h:42)
Error [252] C:\Users\Zwi\Desktop\mplab 232 teste\main.c; 44.1 argument 0 conflicts with prototype
Warning [358] C:\Users\Zwi\Desktop\mplab 232 teste\main.c; 99.18 illegal conversion of pointer to integer



and also maybe instead of the '/o' it should be '/n'?


i would like to send like 123 and to receive 123 not 1,2,3 :p



Best regards,
Zwi
 
Last edited:

The return type of the definition is 'char *' while the declaration is 'void'.

char *Receive_MSG(char *String, unsigned short int MSG_Length)

void Receive_MSG(char *String, unsigned short int MSG_Length);
 
Zwilorg

Had you declared this function at header file ? ( .h )

+++
 
@mym786

Thank you for the input.
you mean that i should get the
void Receive_MSG(char *String, unsigned short int MSG_Length); on the header file and leave the function as it is??

trying with the void on the usart.h i get the following errors:

Error [984] C:\Users\Zwi\Desktop\mplab 232 teste\usart.c; 29.1 type redeclared
Error [1098] C:\Users\Zwi\Desktop\mplab 232 teste\usart.c; 29.1 conflicting declarations for variable "Receive_MSG" (C:\Users\JorgeMachado\Desktop\mplab 232 teste\usart.h:43)
Error [204] C:\Users\Zwi\Desktop\mplab 232 teste\usart.c; 46.14 void function can't return a value


@andre_teprom

which function? i am lost :S if it was the Receive_MSG() yes i did ^^
 

You have to remove "string" from "return string". You cant return anything from a void function.
 
You have to remove "string" from "return string". You cant return anything from a void function.


Done and done! that error is no more thank you ;)

i am really no good at C... i am so used to others (matlab, vb) that this one is weird....


i am trying to remove the error of the "conflicting declarations for variable "Receive_MSG""

i will try and make one following the same principles in the main.c and see what happens





-------------------------------

So on main.c i have as


Code:
char *s

if(RCIF)
{
input= getch();	// read a response from the user

if(Index !='\0')
	{
		Index = getch();
		*s = Index;
		*s++;
	}	
}

and i still have the error

Error [1098] C:\Users\Zwi\Desktop\mplab 232 teste\main.c; 34.26 conflicting declarations for variable "Index"

i looked up to a number of codes just like lcd puts of arrays and so on and they are just like that... :S

anyone knows why this is happening?

*EDIT:

found out why, it seems that Index variable is already used somewhere in the libraries of hi tech compiler...
i used ii where the Index is and it runs now! but i get no proper results....
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top