|
|
Re:problem setting the EUART speed
|
|
Date: 2006/07/30 21:55
|
By: dariog
|
Status: User
|
|
|
Karma: 6  
|
|
| Posts: 107 |   | |
|
Hi Hasan, well my project is a wireless replacement for a home-automation wired (RS485) system that we developed back in 1996 and restructured in 2002. While home automation is still a "secret wish" for most people, our solution does work but we have got no clients for this... we live on other projects 
Nonetheless, I find domotic soooo interesting, and that's why we go on with this.
I developed the protocol, which has some basic fields like Sender, Destination, Command, DATA-payload... Checksum, FrameControl ... ACK packets. The protocol uses a kind of CSMA-CD on RS485 wired, and I wanted to use something similar in RF. I also tried Chipcon 2420 (without Zigbee) and indeed it was much more complex and powerful (register to read RF power, Channel selection on a wide range, SPI interface, hardware Checksum)... but LPRS is not bad too. I could go a bit farher (but no longer than 20 mt indoor) with 900MHz LPRS, compared to 10-12 with 2.4GHz Chipcon. It's still too short, yet suitable for some apps: I want to find out 2 classes of devices, for short and long range. The "repeater" node is something I don't want to deal with, right now.
We can keep in touch, as the thing moves on.
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/07/31 10:57
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
oh yeah, we sure should  and hey, its more that a "secret wish" in my case.. hehe.. i guess all electronic engineers would wanna do it.. we love circuits and everything abut it.. so the first thing that would come to mind is probably home automation.. hehe.. and you guys are doing it, bravo! superb project. see ya around
Hasan
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/01 08:23
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
Hi dariog, since u are using ER900TRS, i wanna to ask you something... are u using the Host Ready Input (pin 7) and Busy output (pin 4) pins..? or u are just using the serial in and out pins connected to UART of the PIC..?? thats what i'm doing right now actaully. i have the host ready pin grounded thought. but it seems like there is a large error in the data tx. and if i were to receive data do i have to use host ready pin (conn to PIC and toggle when ever necessary)..? or can i leve it grounded or open..?? the datasheet is a bit confusing. according to the application example given they have the host ready pin grounded, thats y i'm doing it. can the error be some other problem...? i'm fairly new to RF so things that i think would work "theoretically" may give me problems, right..??  any additional advice..? thanks a lot.
Hasan
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/01 16:33
|
By: dariog
|
Status: User
|
|
|
Karma: 6  
|
|
| Posts: 107 |   | |
|
Yes, I'm using them. I had some trouble with their datasheet too, but then it came to work almost as predicted  You should think of one as a kind of "data ready" from radio to PIC, then read them; the other is a kind of "buffer clear" (if I'm not wrong). I'm checking them later. Anyway I don't think you can avoid using them: otherwise it would be hard to understand and stay in sync with the radio.
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/01 19:36
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
yeah, that make more sence.  thanks a lot. will let u know know how it works out...
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/05 18:51
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
Hi Dariog, I have been working on the RF part last few days.. and tried to configure it so that i'm sure abut the frequency i'm transmitting. So i wrote a function to do that.. following is a part of it. in this part i'm just trynig to configure the baud rate -same thing i'm repeating for the frequency. but it's not sucessful for what ever reason. not even setting the baud rate part.. (i'm lighting up RB5 if sucess, but it dosent light up) so i would like to know if my prob is with the way i'm trying to read from the TRS.. i tried with buffer = getcUSART(); (where buffer is a char variable) initially in a for loop (i have commenterd it out now, pls have a look at the code below.). or my whole aproach.. I also tried with getsUSART( buffer, 9); (where buffer is a srting array of 9).. but this dosent seem to work either.. i tried this coz datasheet doset specify how the echo is.. or does it matter..?? sorry this is a very lengthy post.. but i'm working like a blind man now. totall stuck. could you pls help me out. may be le me know how u are doing, i'll work from there. and thanks for the help. 
//here is the function i wrote.. void RFinitialize(){ char cmdBaud[] = "ER_CMD#U4"; //19200 baud char cmdFreq[] = "ER_CMD#C7"; //434MHz char buffer[9]; int sucess =1; int i;
// open USART with baud of 19200 for 20MHz OpenUSART(USART_RX_INT_OFF & USART_TX_INT_OFF & USART_ASYNCH_MODE & USART_NINE_BIT & USART_CONT_RX & USART_BRGH_LOW,38);
baudUSART(BAUD_8_BIT_RATE & BAUD_WAKEUP_OFF & BAUD_AUTO_OFF);
SPBRGH=0;
//sending first configuration command to the RF module while(PORTBbits.RB0==1){} //checking to see if trs is busy putrsUSART("ER_CMD#U4"); while(BusyUSART()); Delay1KTCYx(600); //delay of abut 30mS at 20MHz oscillation //at least 20 mS required by the RF unit
PORTBbits.RB5=1; //sending the host ready while(!DataRdyUSART()) {} // see if there ia ny data getsUSART( buffer, 9); //try to read the echo from the trs
for(i=0; i<9; i++){ // while(!DataRdyUSART()) {} //buffer = getcUSART(); if(buffer[i] != cmdBaud[i]){ sucess = 0; } } PORTBbits.RB5=0; //host ready disables Delay1KTCYx(600); if(sucess == 1){ while(PORTBbits.RB0==1){} //checking for busy putrsUSART("ACK"); while(BusyUSART()); PORTBbits.RB5=1; //checking to see if it was sucess }//first command send sucessfully
Delay1KTCYx(1000); //a delay to reduce the complication in the //USART speed //end sending first command } // i have cut short the function just to show one sending event.. omitted the frequency setting bit which is basically a copy of this bit..
thanks a lot.
Hasan
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/09 08:55
|
By: dariog
|
Status: User
|
|
|
Karma: 6  
|
|
| Posts: 107 |   | |
|
Hi Hasan, sorry, I've been out for a while.
Well, I do almost the same as you:
putrsUART(ER_CMD); putrsUART("#U4"); // set baud rate halWait(5000); RECEIVE_DATA(myBuf,9); putrsUART(ER_ACK); halWait(20000);
// Set the RF channel halRfSetChannel(rfSettings.channel=channel);
putrsUART(ER_CMD); putrsUART("#P9"); // set power halWait(5000); RECEIVE_DATA(myBuf,9); putrsUART(ER_ACK); halWait(20000); // etc.
(some of the things you'll see in my code have that name because I started out with API for Chipcon CC2420, then I tried to reproduce the RF-layer with ER900... leaving function and their names as they were!)
I remember that I had some trouble too (this was some months ago), and I ended up re-writing some of USART functions.
First, if you look at the source of putrsUSART in the src directory of MCC18, you'll see that it DOES send the terminating NULL character in a string. While the ER900 does not want it.
So I rewrote that (I'm using software UARTS, because the same project has to work on a 18F1320 where the USART pin where already used...):
void putrsUART(rom const char *data) {
do { // Transmit a byte putcUART(*data++); } while(*data); }
As for receive, I'm using a RECEIVE_DATA, which is like this:
char RECEIVE_DATA(char *myBuf,unsigned char len) { char i;
// halWaitFifoByte(); LATBbits.LATB0=0; i=getsUART(myBuf, len); LATBbits.LATB0=1; halWait(5000);
return i; }
and the corresponding
unsigned char getsUART(char *buffer, unsigned char len) { static /*overlay*/ unsigned char i,d; // Length counter
INTCONbits.GIE=0; for(i=0; i<len; i++) { // Only retrieve len characters d = getcUART(); // Get a character from the USART if(uartstatus & 1) { break; } *buffer++ = d; // and save in the string // & Increment the string pointer } INTCONbits.GIE=1; return i; }
(NB halWait merely waits for milliseconds given)
I put these functions in a module which gets included in the project, thus avoiding standard libraries in this case. One more thing I struggled with, was that the standard "read" function, would wait forever for a byte coming from the USART... while of course I wouldn't want to. So I rewrote it too to include a time out... but I'm not sure if this applies to hardware USART too. We'll check it later.
I
Post edited by: dariog, at: 2006/08/09 09:55
Post edited by: dariog, at: 2006/08/09 09:56
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/09 12:31
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
Hi Dariog, Thanks for the reply... Well, it looks fairly similar to me too. i mean ur method and the way i was doing it. may be the prob is created by the null string then..? also i see that in ur RECEIVE_DATA fuction u have LATBbits.LATB0=0; (which i believe is setting the "host ready" signal) but what i undestood from the datasheet hostready pin of the transceiver has to be put to Hi to receive data. but you are putting it to LO.. did i get something wrong here, or that line is code is not what i'm assuming it to be (host ready)? and i'm not questionang ur method, but just curious  and one other thing.. in the RECEIVE_DATA func, i see u are returning i (a local variable to the func), but when u are calling u are just calling as RECEIVE_DATA(myBuf,9); i couldnt really figure out what that i does. one more qn... I dont see you checking the echo; if it actaully echored the right characters., are u using the fast ack method..? that sending 0x06 as ACK.. thanks for ur help. 
Hasan
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/09 12:31
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
Hi Dariog, Thanks for the reply... Well, it looks fairly similar to me too. i mean ur method and the way i was doing it. may be the prob is created by the null string then..? also i see that in ur RECEIVE_DATA fuction u have LATBbits.LATB0=0; (which i believe is setting the "host ready" signal) but what i undestood from the datasheet hostready pin of the transceiver has to be put to Hi to receive data. but you are putting it to LO.. did i get something wrong here, or that line is code is not what i'm assuming it to be (host ready)? and i'm not questionang ur method, but just curious  and one other thing.. in the RECEIVE_DATA func, i see u are returning i (a local variable to the func), but when u are calling u are just calling as RECEIVE_DATA(myBuf,9); i couldnt really figure out what that i does. one more qn... I dont see you checking the echo; if it actaully echored the right characters., are u using the fast ack method..? that sending 0x06 as ACK.. thanks for ur help. 
Hasan
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/09 17:38
|
By: dariog
|
Status: User
|
|
|
Karma: 6  
|
|
| Posts: 107 |   | |
|
majestrix wrote:
Well, it looks fairly similar to me too. i mean ur method and the way i was doing it. may be the prob is created by the null string then..?
yeah, I hope so 
also i see that in ur RECEIVE_DATA fuction u have LATBbits.LATB0=0; (which i believe is setting the "host ready" signal) but what i undestood from the datasheet hostready pin of the transceiver has to be put to Hi to receive data. but you are putting it to LO.. did i get something wrong here, or that line is code is not what i'm assuming it to be (host ready)?
oh, well, on page 2 of 10 of a datasheet named "easyradio ER900FHTRS 1-4 Iss 1-3 April 2003" I see that you have to pull dat pin down in ordr to have LPRS transmitting out its bytes. But I saw many flavours of that datasheet so maybe you've got a different one. The one I trusted more (though I don't remember any contradiction, just less clarity among the datasheets) says that LPRS goes "Busy Output" when has gotten enough bytes to send on the air, and that Host REady is low when the Host is Ready to receive from LPRS.
and one other thing.. in the RECEIVE_DATA func, i see u are returning i (a local variable to the func), but when u are calling u are just calling as RECEIVE_DATA(myBuf,9); i couldnt really figure out what that i does.
it merely returns the #of chars read, so it's a kind of confirmation (that I don't even use, at the time...)
one more qn... I dont see you checking the echo; if it actaully echored the right characters., are u using the fast ack method..? that sending 0x06 as ACK..
No, I'm not using FAST-ACK. I simply ignore the return value... at the moment.
|
|
|
|
|
|
Re:problem setting the EUART speed
|
|
Date: 2006/08/09 17:52
|
By: majestrix
|
Status: User
|
|
|
Karma: 0  
|
|
| Posts: 29 |   | |
|
Hi Dariog, well it seems like we are having two different datasheets after all.. anyhow i checked with hostready pin HI today and was able to implement the link.. for configuration i'm directly connecting to PC with a MAX232 and configuring it.. not the best solution, but as long as it works right..? thanks for the help man.
Hasan
|
|
|
|