SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By jele
#44188
Hi all i have problem :cry: when i send data from pipe A and pipe B together
data is confuse how to do it. Please analyse my code


MY CODE::(Receive) :oops:

unsigned char data, status, pipe; //register to hold letter received and sent
unsigned char Buff_Pipe_A[37] , Buff_Pipe_B[37] ;
unsigned char Cnt_Pipe_A = 0 , Cnt_Pipe_B = 0 , Cnt_Pipe_C = 0 ;
unsigned char Snt_Pipe_A = 0 , Snt_Pipe_B = 0 , Snt_Pipe_C = 0;
unsigned char F_Pipe_A = 0 , F_Pipe_B = 0 , F_Pipe_C = 0;


/*********************************************************\
* Configuration MCU *
\*********************************************************/
#pragma config OSC = HSPLL, OSCS = OFF
#pragma config PWRT = ON, BOR = ON, BORV = 45
#pragma config WDT = OFF, WDTPS = 1
#pragma config MODE = MC, WAIT = OFF
#pragma config CCP2MUX = OFF
#pragma config STVR = ON, LVP = OFF
#pragma config DEBUG = OFF

/*********************************************************\
_..-------++._
_.-'/ | _|| \"--._
__.--'`._/_\j_____/_||___\ `----.
_.--'_____ | \ _____ /
_j /,---.\ | =o | /,---.\ |_
[__]==// .-. \\==`===========/==// .-. \\=[__]
`-._|\ `-' /|___\_________/___|\ `-' /|_.'
`---' `---'
\*********************************************************/
void main(void)
{
Initialize(); //initialize PLL, IO, SPI, set up nRF24L01 as RX
//main program loop
Cnt_Pipe_A = 0 , Cnt_Pipe_B = 0;
Snt_Pipe_A = 0 , Snt_Pipe_B = 0;
F_Pipe_A = 0 , F_Pipe_A = 0;
while(TRUE)
{
//wait until a packet has been received
while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()));
status = nrf24l01_read_rx_payload(&data, 1);
pipe = nrf24l01_get_rx_pipe_from_status(status);
nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01

switch(pipe)
{
case 0:
Buff_Pipe_A[Cnt_Pipe_A] = data;
Cnt_Pipe_A++;
if(Cnt_Pipe_A > 35)
{
F_Pipe_A = 1;
}
break;

case 1:
Buff_Pipe_B[Cnt_Pipe_B] = data;
Cnt_Pipe_B++;
if(Cnt_Pipe_B > 35)
{
F_Pipe_B = 1;
}
break;
//default:
}
//Send Data From Pipe 0
if(F_Pipe_A == 1 && (F_Pipe_B == 0))
{
putc1USART('*');
while(Busy1USART());
Delay100TCYx(50);
putc1USART('a');
while(Busy1USART());
Delay100TCYx(50);
for(Snt_Pipe_A = 0 ; Snt_Pipe_A < 36 ; Snt_Pipe_A++)
{
putc1USART(Buff_Pipe_A[Snt_Pipe_A]);
while(Busy1USART());
Delay100TCYx(50);
}

Cnt_Pipe_A = 0;
F_Pipe_A = 0;
}
//Send Data From Pipe 1
if((F_Pipe_A == 0) && (F_Pipe_B == 1))
{
putc1USART('*');
while(Busy1USART());
Delay100TCYx(50);
putc1USART('b');
while(Busy1USART());
Delay100TCYx(50);
for(Snt_Pipe_B = 0 ; Snt_Pipe_B < 36 ; Snt_Pipe_B++)
{
putc1USART(Buff_Pipe_B[Snt_Pipe_B]);
while(Busy1USART());
Delay100TCYx(50);
}
Cnt_Pipe_B = 0;
F_Pipe_B = 0;
}
/*
nrf24l01_read_rx_payload(&data, 1); //read the packet into data
nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
putc1USART(data);
while(Busy1USART());
*/
ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed
} // While True ....
} // Main()...
By brennen
#44195
There is no such thing as pipes A and B. I'll assume that you are referring to pipes 0 and 1, as this is how they are named in the datasheet. Does your code work if you only send from pipe 0? If not, you need to go back and make sure you can get the tutorial main code working as-is with your hardware by only changing the appropriate #define's in nrf24l01.h. Then build up from there.
By jele
#44258
Yes, My code it very work when i only sent from pipe 0
By brennen
#44424
Since I can't see your initialization code, I'm not sure that you have both pipes 0 and 1 enabled. If I were you, I would start with the code from Tutorial 3, because it uses all 5 pipes. If you can get that code running on your hardware, then you should be able to get multiple pipes going by simply modifying the main file to get it to do what you want. Keep in mind that Tutorials 1 & 2 only enable pipe 0, so if you were sending on pipe 1, you would never receive the data.
By jele
#44683
Thank you very much for the best suggestion :P :D .Now i'am initialed with tutorioal 3 and code it work .Target of my project is "Receive data(from sensor) from 6 pipe and send out to usart1 " i have length of data from eack sensor 45 character is receive each pipe how to separability all data
and send to serial!

sensor 1 ------------------------>> pipe1
sensor 2 ------------------------>> pipe2
sensor 3 ------------------------>> pipe3

and sent all data to serial

how to do below or Algorithm?
This target of data packgate :?
[1,--------Data from pipe 1----------] \
[2,--------Data from pipe 2----------]----uart1 (115200 bps)--->[computer]
[3,--------Data from pipe 3----------] /

At this time my data is confuse :oops:

-][1,--------Data from pipe 1---------

-][2,--------Data from pipe 2---------

How to resolution this problem?
By brennen
#44693
jele wrote:i have length of data from eack sensor 45 character is receive each pipe how to separability all data and send to serial!
Keep in mind that the largest amount of data you can send in one packet is 32 with the 24L01, which means you will have to send two packets to get 45 characters.
jele wrote:how to do below or Algorithm?
This target of data packgate
[1,--------Data from pipe 1----------] \
[2,--------Data from pipe 2----------]----uart1 (115200 bps)--->[computer]
[3,--------Data from pipe 3----------] /

At this time my data is confuse

-][1,--------Data from pipe 1---------

-][2,--------Data from pipe 2---------

How to resolution this problem?
First you have to make sure that in the nrf24l01_initialize function, you set up each pipe's data payload width to the right number of bytes. You also have to make sure you transmit this same number of bytes from each of the sensor nodes. Each sensor would then send its data to the address of the proper pipe. Then the reciever would gather the data and send it on its way down the serial pipe.

You will likely need to have some sort of acknowledgement mechanism (whether that be the hardware auto-acknowledge or your own in software), unless you can afford to lose some data occasionally (and you certainly will, even in the best conditions).

You should start out just making sure that you can send data from one sensor node to your base receiver. After that, add another sensor, and get that working. Then add the third sensor. Once you get that working, you should be able to manage putting the data together.

One thing you will have to do in software is to somehow make sure that none of the sensors is transmitting at the same time. Possible implementations would be to use a timer of some sort at the sensor end, send a message from the receiver base station to a single sensor first and wait for it to send data, or a multitude of others.[/quote]
By jele
#44773
Thank again Brennen :lol: but i have a little problem .
Now i test for single pipe (code in totorial3) i send a single charactor from remote to local and show it on hypertherminal . I send charactor continue and delay 130 Us/Charactor ('a' /DelayUS(130)/ 'b' / DelayUS(130) / 'c' / DelayUS(130))) i send it continue about 2 munite data it loss about 1 charactor per time please tell me about this problem or is normal data is loss!!. How i solv problem?

-use code tutorial 3(Multiple pipe)
-mcu 18f8720 + x-tal 10 MHz
-compiler MPLAB v8.02 + c18
-distance beteween Local module and Remote module about 30 cm.
-boudrate 115200 bps

help me please!! :oops:
By jele
#44836
Now! i want to use interrupt IRQ but it my code not work please tell me about my code it can't receive when i connect IRQ into pin RB1

-I define port RB1 is IRQ
-I use interrupt external INT1

/*
***********************************************************
** Function Interrup Subroutine
***********************************************************
*/
#pragma code HIGH_INTERRUPT_VECTOR = 0x08
void High_Interrupt_Handler(void)
{
_asm goto WIFI _endasm
}
#pragma code

#pragma interrupt WIFI
void WIFI(void)
{
if(INTCON3bits.INT1IF)
{
while(!nrf24l01_irq_rx_dr_active());
status = nrf24l01_read_rx_payload(&Data_wifi, 1);
pipe = nrf24l01_get_rx_pipe_from_status(status);
nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
switch(pipe)
{
case 0:
putc1USART(Data_wifi);
while(Busy1USART()); break;

case 1: putc1USART(Data_wifi);
while(Busy1USART());
break;
}

INTCON3bits.INT1IF = 0; //Clear bit frag inerrupt
}
}

/*
***********************************************************
** Initial Interrupt External
***********************************************************
*/
void EnableHighInterrupt(void)
{
OpenRB1INT(PORTB_CHANGE_INT_ON &
PORTB_PULLUPS_OFF &
FALLING_EDGE_INT );

RCONbits.IPEN = 1; //Enable priority level on interrupts
INTCONbits.GIEH = 1; //Enable interrupt
INTCON3bits.INT1IE = 1; //Enable interrupt
}


Thank you very much :P