CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC-to-PIC Communication / Easy-radio help needed

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
AA



Joined: 13 May 2005
Posts: 3

View user's profile Send private message

PIC-to-PIC Communication / Easy-radio help needed
PostPosted: Tue May 31, 2005 8:54 am     Reply with quote

PROBLEM 1 - needs to be solved before problem 2


Im trying to comminicate between two pics using the rs232, im sending a simple 'F' to the reciever PIC (both 18F452). The reciever pic is connected to a PC and im monitoring the program using the hyperterminal.

Well the code (that doest work..) looks like this:

TRANSMITTER
-------------------------------
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12

void main (){
int k;
output_b(0x00); //
set_tris_b(0x00); // RB0 = input, resten output
while (1){
while(1){
putc('F');
output_high(PIN_B1);}
}
}

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

RECIEVER
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
long k=0;
char dato;

#INT_RDA
RECEPT_INTERRUPT()
{
printf("\n\r INTERRUPT\n");
if(kbhit()) {
dato=getc();
printf("\rRecieved: %u times looped: %lu",dato,k);}
}

void go(){
output_high(diod5);
delay_ms(10);
output_low(diod5);
delay_ms(10);
/*dato=getc();*/
k++;

}
void init(){
enable_interrupts(int_rda);
ENABLE_INTERRUPTS(GLOBAL);
printf("\n\rSTARTING\n");
output_b(0x00);
set_tris_b(0x00);
}
void main (){
printf("\n\rStart 1");
init();
delay_ms(100);
while(1){
go();
}
}
------------------
HYPERTERMINAL

The hyper terminal says the following if i run the program for lets say 1 minute:
----------------
Start 1
INTERRUPT
Recieved: 0 times looped: 0
STARTING

INTERRUPT
Recieved : 70 times looped: 35
INTERRUPT
Recieved: 70 times looped: 35
-----------------
after this nothing more happens no mather how long i run it.


Any help appreciated as im running out of time badly




Problem 2, is a problem because problem 1 exists, well:Im trying to radiocontrol a robot with help from Easy-Radio:
DATASHEET

Well im trying to send simple go forward, back, left etc but i cant get the radio communication to work at all :( even if it says simple and my projekt time is running out bad :(

Oh and the PIC:s i use are 2x18F452 (transmitter and reciever)

On the transmitter i have connected:

PIN 1 (RF GND) - GND
PIN 2 (RF OUT) - Antenna
PIN 3 (Vcc) - +5V
PIN 4 (Gnd) - GND
PIN 5 (TXD) - RC6/TX on the pic (18F452)

On the reciever

PIN 1 (Antenna) - Antenna
PIN 2 (RF Gnd) - GND
PIN 3 (RSSI) - Inget
PIN 4 (Busy output) -GND
PIN 5 (Serial data out) - RC7/RX on pic
PIN 6 (Serial data in) - +5v
PIN 7 (Host ready input) - GND
PIN 8 (Vcc) - +5v
PIN 9 (Ground) - GND


The transmitters code is like this:

while (1){

printf("\n Sending...");
}

if i connect RC6 på the transmitter pic toMAX232 and the hyperterminal så i do get the correct print - >
Sending...
Sending...
etc..

And the recivers code is

char radioinput = 0;
int k=0;
while(1){
radioinput=getc();
printf("\rRadio input: %u varv:",radioinput,k);
}


It goes one loop (k) and then i halts andi guess it is because it doesnt get anything on the getch().

Both PIC:s are initiated like this:


#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)



Im very happy over all the help i can get! Smile
Ttelmah
Guest







PostPosted: Tue May 31, 2005 3:07 pm     Reply with quote

Read all the posts about keeping interrupt handlers _short_. Your transmit code is sending 'F' characters flat out. The receive code, interrupts, and before it even attempts to read the character, spends 13 character times printing a message. This _will not work_. The fact that the intetrrupt occurs, means there is a character waiting to be read (you do not need to use 'kbhit'), and it _must_ be read inside two character times, or the UART buffers will overflow.
Look at the siow.c example, on how to buffer a received character, and do _all_ your other work in the main code. Even with buffering, the buffer _will_ overflow if a single incoming character triggers a message more than one character long.
Also add 'ERRORS' to your RS232 setup in the receiver, which will clear the overrun error, and allow the code to continue (though not make it work properly as written).

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group