Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joining nrf module to esp wifi network #16

Closed
dekundu opened this issue Jun 27, 2016 · 22 comments
Closed

Joining nrf module to esp wifi network #16

dekundu opened this issue Jun 27, 2016 · 22 comments

Comments

@dekundu
Copy link

dekundu commented Jun 27, 2016

Hi,
I quite did not understand the purpose of RF24Ethernet library. With this can I directly communicate between a nrf module and a esp 8266.
Currently I have arduino+nrf at one side, and at the other end I have esp8266+nrf. This works :). I am using RF24Mesh library in order to achieve this. Can I just remove the nrf at the esp end, and join the esp created network (esp soft ap mode) from the arduino+nrf24l01 setup using the RF24Ethernet library?
Thanks,
Debojit

@TMRh20
Copy link
Member

TMRh20 commented Jun 28, 2016

These are the general models for RF24Ethernet and RF24Mesh with ESP8266:

RF24Ethernet:

Arduino -> RF24 -> RPi (RF24Gateway) -> WiFi / LAN / Internet / ESP8266 /
etc.

RF24Mesh:

Arduino -> RF24 -> ESP8266 -> TCP/IP -> LAN/Internet

Technically the ESP8266 could act as a LAN/Internet gateway, just like RPi,
but RF24Ethernet currently uses a separate TCP/IP stack, so this is not
implemented. Users can program the ESP to pass information between RF24 and
external networks.

On Mon, Jun 27, 2016 at 1:33 AM, Debojit Kundu notifications@github.com
wrote:

Hi,
I quite did not understand the purpose of RF24Ethernet library. With this
can I directly communicate between a nrf module and a esp 8266.
Currently I have arduino+nrf at one side, and at the other end I have
esp8266+nrf. This works :). I am using RF24Mesh library in order to achieve
this. Can I just remove the nrf at the esp end, and join the esp created
network (esp soft ap mode) from the arduino+nrf24l01 setup using the
RF24Ethernet library?
Thanks,
Debojit


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#16, or mute the thread
https://github.com/notifications/unsubscribe/ACfVHKX7gDTouWTiYQNzm-CtkMsC4m7rks5qP3zggaJpZM4I-08b
.

@cjmcx
Copy link

cjmcx commented Dec 21, 2019

hi TMRh20
I have a transmiter made with pic16f689(clasic example from hoperf) , work OK
I want to transmit same buf with esp 32
two esp32 work togeder
my problem is pic transmit (W_TX_PAYLOAD_NO_ACK, &got_time, sizeof(unsigned long)), but your library can t like that

@cjmcx
Copy link

cjmcx commented Dec 21, 2019

sorry for English

@TMRh20
Copy link
Member

TMRh20 commented Dec 23, 2019 via email

@cjmcx
Copy link

cjmcx commented Dec 23, 2019 via email

@TMRh20
Copy link
Member

TMRh20 commented Dec 23, 2019 via email

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

`#include <SPI.h>

#include "nRF24L01.h"
#include "RF24.h"

RF24 radio(17, 5);
//const byte rxAddr[6] = "00001";
//const uint64_t pipes[2] = { 0x1001013443LL, 0x39383736c2LL };

const uint64_t pipes[2] = { 0x3443101001LL, 0x39383736c2LL };

// pic16f690 pipe configuration
//const UINT8 RX0_Address[]={0x34,0x43,0x10,0x10,0x01};//Receive address data pipe 0
//const UINT8 RX1_Address[]={0x39,0x38,0x37,0x36,0xc2};////Receive address data pipe 1

void setup()
{
//while (!Serial);
Serial.begin(9600);

radio.begin();
//radio.openReadingPipe(0, rxAddr);
radio.openReadingPipe(0, pipes[0]);
radio.openReadingPipe(1, pipes[1]);
radio.setChannel(0x06);
//radio.printDetails();
radio.startListening();
radio.printDetails();

}

void loop()
{
if (radio.available())
{
char text[32] = {0};
radio.read(&text, sizeof(text));
Serial.print("Received : ");
Serial.println(text);
} else {
//Serial.println("No Singal");
//delay(500);
}
}`

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

rx esp32

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

tx esp32
#include <SPI.h>

#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(17, 5);

//const byte rxAddr[6] = "00001";
const uint64_t pipes[2] = { 0x3443101001LL, 0x39383736c2LL };

void setup()
{
Serial.begin(9600);
Serial.println("Start....");
radio.begin();
//radio.setRetries(15, 15);
radio.enableDynamicAck();
//radio.openWritingPipe(rxAddr);
radio.openWritingPipe(pipes[0]);
radio.setChannel(0x06);
radio.printDetails();
radio.stopListening();
}

char text[] = "DIANA I'm Here !!";
int counter = 0;
void loop()
{
// if (counter <10) {
// text[0] = '0';
// text[1] = char(counter + 97);
// counter++;
// }
// else {
// counter = 0;
// }

Serial.print("Sending.....");
radio.write(&text, sizeof(text),1);
Serial.print("OK : ");
Serial.println(text[1]);
delay(100);
}``

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

pic rx
` /*********************************************************
copyright(c) 2010
Title: RFM70 simple example based on PIC c
Current version: v1.0
Function: RFM70 demo
processor: PIC16F690
Clock: 8M Crystal
Author: baiguang(ISA)
Company: Hope microelectronic Co.,Ltd.
Contact: +86-0755-82973805-846
E-MAIL: rfeng@hoperf.com
Data: 2010-6-18
*/
/

---------------
VDD---- |VDD VSS| ----GND
SW_1---- |RA5 RA0| ----
sensitive_LED---- |RA4 RA1| ----VDD
IRQ---- |RA3 RA2| ----CE
PWM OUT---- |RC5 RC0| ----CSN
PWM OUT---- |RC4 RC1| ----SCK
SW_2 ---- |RC3 RC2| ----MOSI
hall ---- |RC6 RB4| ----MISO
DS ---- |RC7 RB5| ----RX
TX ---- |RB7 RB6| ----V_rez
---------------
pic16F690
*********************************************************/
#include "ssrRFM70.h"
#include "built_in.h"

#define SW_1 PORTA.F5 //RB4
#define RED_PWM PORTC.F5 //RB5
#define GREEN_PWM PORTC.F4
#define Sensitive_LED PORTA.F4 //RB6
#define V_rez PORTB.F6
#define SW_2 PORTC.F3 //RC7
#define hall PORTC.F6 //RC6
#define DS PORTC.F7

#define SW_1_DIR TRISA.F5 //=0;
#define RED_PWM_DIR TRISC.F5 //=0;
#define GREEN_PWM_DIR TRISC.F4 //=0;
#define Sensitive_LED_DIR TRISA.F4 //=0;
#define V_rez_DIR TRISB.F6 // =0;
#define SW_2_DIR TRISC.F3 //=1;
#define hall_DIR TRISC.F6 //=1;
#define DS_DIR TRISC.F7 //=1;

UINT8 remclose;
UINT8 invata;
UINT8 temp_buf[32];

typedef struct
{

unsigned char reach_1s				: 1;
unsigned char reach_5hz				: 1;

} FlagType;

FlagType Flag;

void init_mcu(void);
void init_port(void);
void timer2_init(void);

void power_on_delay(void); // 1
void delay_2s(void); // 2
void delay_200ms(void); // 3
void delay_50ms(void); // 4
void delay_5ms(void); // 5
void delay_1ms(void); // 6
void delay_20us(void); // 7

void sub_program_1hz(void);
void inchide(void);
void re_inchide(void);
void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len);
void Send_NACK_Packet(void);
void Receive_Packet(void);
void SPI_Bank1_Write_Reg(UINT8 reg, UINT8 *pBuf);
void SPI_Bank1_Read_Reg(UINT8 reg, UINT8 *pBuf);
void Carrier_Test(UINT8 b_enable); //carrier test
void direct(void);
void indirect(void);

extern void RFM70_Initialize(void);
extern void SwitchToTxMode(void);
extern void SwitchToRxMode(void);

const UINT8 tx_buf[19]={0x44,0x4F,0x41,0x4E,0x20,0x47,0x4F,0x43,0x41,0x4E,0x20,0x54,0x48,0x45,0x20,0x42,0x45,0x53,0x54};
UINT8 rx_buf[MAX_PACKET_LEN];

extern const UINT8 RX0_Address[];
extern const unsigned long Bank1_Reg0_13[];

UINT8 test_data;

/*********************************************************
Function: init_mcu();

Description:
initialize mcu.
*********************************************************/
void init_mcu(void)
{
// init_comms();
init_port();
timer2_init();
}

/*********************************************************
Function: init_port();

Description:
initialize port.
*********************************************************/
void init_port(void)
{
ANSEL = 0;
ANSELH = 0;
WPUB = 0;

CE_DIR = 0;
CSN_DIR = 0;
SCK_DIR = 0;
MISO_DIR = 1;
MOSI_DIR = 0;

GND_DIR = 0;
VDD_DIR = 0;
// IRQ_DIR = 1;

RED_PWM_DIR       = 0;
GREEN_PWM_DIR     = 0;
Sensitive_LED_DIR = 0;
SW_1_DIR          = 1;
SW_2_DIR          = 1;

// SW_3_DIR = 1;
// L293_DIR = 0;
V_rez_DIR = 0;
hall_DIR = 1;
DS_DIR = 1;

CE                = 0;
CSN               = 1;
SCK               = 0;
MOSI              = 0;

GND = 0;
VDD = 0;
RED_PWM = 0;
GREEN_PWM = 0;
Sensitive_LED = 0;
// L293 = 0;
V_rez = 1;
SW_1 = 0;
SW_2 = 0;
// SW_3 = 0;
hall = 0;
}
/*********************************************************
Function: timer2_init();

Description:
initialize timer.
*********************************************************/
void timer2_init(void)
{
T2CON = 0x04; // timer2 on and 16 pre, postscale
// PR2 = 156; // 50hZ, 4m/4/16/16/50
pie1.TMR2IE = 1;
}

/*********************************************************
Function: interrupt ISR_timer()

Description:

*********************************************************/

/*
void interrupt (void)
{
// di();
unsigned char i;
if(TMR2IF)
{

if((Sensitive_LED)||(aaa))
{
		aaa++;

// if(aaa==400)
if(aaa==20)
{
Sensitive_LED = 0;
}
// if(aaa==420)
// {
// RED_LED = 1;
// }
// if(aaa==2220)
if(aaa==440)
{
aaa = 0;
// RED_LED = 0;
}
}
// if((Sensitive_LED)||(RED_LED))
// {
// aaa++;
// }
// if(aaa==20)
// {
// aaa=0;
// Sensitive_LED = 0;
// RED_LED = 0;
// }

	count_50hz++;
		if(count_50hz==100)  // REACH 1S
 		{
   			count_50hz=0;
   			Flag.reach_1s = 1;
        mas++;
 		}
 		else if(count_50hz == 5)
 		{
		Flag.reach_5hz = 1;
 		}

  PIR1.TMR2IF=0;
}

}
*/

/*********************************************************
Function: power_on_delay()

Description:

/
void power_on_delay(void)
{
unsigned int i;
for(i = 0; i<1000; i++)
{
delay_1ms();
}
}
/
/
void delay_10s(void)
{
unsigned int i;
for(i = 0; i<10; i++)
{
power_on_delay();
}
}
/
********************************************************/
void delay_200ms(void)
{
unsigned char j;
for(j = 0; j<40; j++)
{
delay_5ms();
}
}

void delay_2s(void)
{
unsigned char j;
for(j = 0; j<10; j++)
{
delay_200ms();
}
}

void delay_300ms(void)
{
unsigned char j;
for(j = 0; j<60; j++)
{
delay_5ms();
}
}

/*********************************************************
Function: delay_50ms();

Description:

*********************************************************/
void delay_50ms(void)
{
unsigned char j;
for(j = 0; j<10; j++)
{
delay_5ms();
}
}

void delay_1ms(void)
{
unsigned char i;
for(i = 0; i<130; i++)
{
;
}
}

void delay_20us(void)
{
unsigned char i;
for(i = 0; i<3; i++)
{
;
}
}

void sub_program_1hz(void)
{
UINT8 i;
// UINT8 temp_buf[32];

	for(i=0;i<19;i++)
	{
		temp_buf[i]=tx_buf[i];
	}

	Send_Packet(W_TX_PAYLOAD_NOACK_CMD,temp_buf,19);
	SwitchToRxMode();  //switch to Rx mode
delay_ms(1000);

}

void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len)
{
UINT8 fifo_sta;

SwitchToTxMode();  //switch to tx mode

fifo_sta=SPI_Read_Reg(FIFO_STATUS);	// read register FIFO_STATUS's value
if((fifo_sta&FIFO_STATUS_TX_FULL)==0)//if not full, send data (write buff)
{

// GREEN_LED = 1;

	SPI_Write_Buf(type, pbuf, len); // Writes data to buffer

	delay_50ms();

// GREEN_LED = 0;
delay_50ms();
//printf("%c",fifo_sta);

}
}

void Receive_Packet(void)
{
UINT8 len,i,sta,fifo_sta,value,chksum,aa;
UINT8 rx_buf[MAX_PACKET_LEN];

sta=SPI_Read_Reg(STATUS);	// read register STATUS's value

if((STATUS_RX_DR&sta) == 0x40)				// if receive data ready (RX_DR) interrupt
{
	do
	{
		len=SPI_Read_Reg(R_RX_PL_WID_CMD);	// read len

		if(len<=MAX_PACKET_LEN)
		{
			SPI_Read_Buf(RD_RX_PLOAD,rx_buf,len);// read receive payload from RX_FIFO buffer
		}
		else
		{
			SPI_Write_Reg(FLUSH_RX,0);//flush Rx
		}

		fifo_sta=SPI_Read_Reg(FIFO_STATUS);	// read register FIFO_STATUS's value

	}while((fifo_sta&FIFO_STATUS_RX_EMPTY)==0); //while not empty

	chksum = 0;
	if(invata)
	{

	for(i=0;i<19;i++)
	{
	eeprom_write(i,rx_buf[i]);

// chksum +=rx_buf[i];
// printf("%c",rx_buf[i]);

	}
	invata = 0;

// GREEN_LED = 0;
}

//for(i=0;<10;i++)
//{
//if(rx_buf[i]==eeprom_read(i)&&aaa==0)
//{
//Sensitive_LED = 1;
//}
//}

// if(rx_buf[i]==eeprom_read(i)&&aaa==0)

	if(rx_buf[0]==eeprom_read(0)&&rx_buf[1]==eeprom_read(1)&&rx_buf[2]==eeprom_read(2)&&rx_buf[3]==eeprom_read(3))

// if(rx_buf[0]==0x49&&rx_buf[1]==0x4F&&rx_buf[2]==0x41&&rx_buf[3]==0x4E&&aaa==0)
{
// L293 = 1;

	if(SW_2==1)
	{
	switch (remclose) {
	case 0: remclose = 1;

// GREEN_LED = 0;
// Sensitive_LED = 1;
// pozitie = 1;
Pwm_Change_Duty(128);
// usart_write(ch);
break;

	case 1: remclose = 0;

// GREEN_LED = 1;
// re_inchide();
Pwm_Change_Duty(0);
// GREEN_LED = 1;
break;
//usart_write(ch);
// case 2: Hi(); break;
// default: Message("Invalid state!");
}
}

		delay_50ms();
		delay_50ms();

// RED_LED = 0;
//printf("%c",sta);
// Send_Packet(W_TX_PAYLOAD_NOACK_CMD,rx_buf,19);
// L293 = 0;
SwitchToRxMode();//switch to RX mode
}
if(rx_buf[0]==0x53&&rx_buf[1]==0x65&&rx_buf[2]==0x74)
eeprom_write(100,rx_buf[3]);

// for(i=0;i<17;i++)
// {
// printf("%c",rx_buf[i]);
// }
}
SPI_Write_Reg(WRITE_REG|STATUS,sta);// clear RX_DR or TX_DS or MAX_RT interrupt flag
// GREEN_LED = 0;
}

void main()
{
unsigned char i, j, pwm_set, chksum;

OSCCON = 0X70;	// 8M crystal
WDTCON = 0X00;
//init_comms();
power_on_delay();
init_mcu();

// usart_init(9600);
// count_50hz = 0;
Flag.reach_1s = 0;
// mas = 0;
// aaa = 0;
// pozitie = 0;
remclose = 0;
invata = 0;
INTCON = 0xc0; // enable interrupt
pwm_init(200000);
ccp1con = 141; // 1000 1101
PWM1CON = 255;
PSTRCON = 3;
RFM70_Initialize();
//RED_LED_DIR = 0;

Pwm_Change_Duty(0);
for(i=0;i<19;i++)
{
temp_buf[i]=tx_buf[i];
eeprom_write(i,temp_buf[i]);
// Sensitive_LED = 1;
// pozitie = 1;
// aaa = 1;
}
eeprom_write(100,5);
while(1)
{

// hallin = hall;
if(SW_1&&invata==0)
{
sub_program_1hz();
delay_2s();
// sub_program_1hz();
}
if(SW_1)
{
invata = 1;
// GREEN_LED = 1;
}

   Receive_Packet();


}

}

`

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

pic tx
`
#include "RFM70.h"
//#include <pic.h>
//#include "usart.h"
//#include "usart.c"

//#define RED_LED PORTB.F4
#define GREEN_LED PORTB.F6
#define SW1 porta.F5
#define SW2 porta.F4

//#define RED_LED_DIR TRISB.F4
#define GREEN_LED_DIR TRISB.F6
#define SW1_DIR TRISa.F5
#define SW2_DIR TRISa.F4

UINT8 count_50hz;
UINT8 aaa; //temporizare actionare motor
UINT8 bbb; //confirmare transmisie-receptie
UINT8 temp_buf[32];
unsigned char confi ;
unsigned char us ;
UINT8* pbuf;
typedef struct
{

unsigned char reach_1s				: 1;
unsigned char reach_5hz				: 1;

} FlagType;

FlagType Flag;

void init_mcu(void);
void init_port(void);
void timer2_init(void);

void power_on_delay(void);
void delay_200ms(void);
void delay_50ms(void);
void delay_5ms(void);
void delay_1ms(void);
void delay_20us(void);
void sub_program_1hz(void);

void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len);
void Send_NACK_Packet(void);
void Receive_Packet(void);
void SPI_Bank1_Write_Reg(UINT8 reg, UINT8 *pBuf);
void SPI_Bank1_Read_Reg(UINT8 reg, UINT8 *pBuf);
void Carrier_Test(UINT8 b_enable); //carrier test

extern void RFM70_Initialize(void);
extern void SwitchToTxMode(void);
extern void SwitchToRxMode(void);
//const char *tx_buf[19]="IOAN GOCAN THE BEST";
const UINT8 tx_buf[19]={0x49,0x4F,0x41,0x4E,0x20,0x47,0x4F,0x43,0x41,0x4E,0x20,0x54,0x48,0x45,0x20,0x42,0x45,0x53,0x54};
const UINT8 dx_buf[19]={0x44,0x4F,0x41,0x4E,0x41,0x20,0x4F,0x41,0x4E,0x41,0x20,0x47,0x4F,0x43,0x41,0x4E,0x20,0x31,0x31};
const UINT8 cx_buf[19]={0x43,0x52,0x49,0x53,0x54,0x49,0x41,0x4E,0x41,0x2E,0x46,0x4C,0x4F,0x52,0x49,0x4E,0x41,0x2E,0x35};
UINT8 rx_buf[MAX_PACKET_LEN];
UINT8 verif;
extern const UINT8 RX0_Address[];
extern const unsigned long Bank1_Reg0_13[];

UINT8 test_data;

void init_mcu(void)
{
// init_comms();
init_port();
timer2_init();
trisc = 0;
portc = 0;
}

void init_port(void)
{
ANSEL = 0;
ANSELH = 0;
WPUB = 0;
WPUA = 0x30;
// usart_init(9600);
CE_DIR = 0;
CSN_DIR = 0;
SCK_DIR = 0;
MISO_DIR = 1;
MOSI_DIR = 0;
IRQ_DIR = 1;
TRISA.F3 = 0;
PORTA.F3 = 0;
// TRISB.F6 = 0;
// PORTB.F6 = 0;
TRISB.F7 = 0;
PORTB.F7 = 0;
TRISC.F6 = 0;
PORTC.F6 = 0;
TRISC.F7 = 0;
PORTC.F7 = 0;
TRISC.F3 = 0;
PORTC.F3 = 0;
TRISC.F4 = 0;
PORTC.F4 = 0;
TRISC.F5 = 0;
PORTC.F5 = 0;
GND_DIR = 0;
VDD_DIR = 0;
SW1_DIR =1;
SW2_DIR =1;
GREEN_LED_DIR = 0;

CE  = 0;
CSN = 1;
SCK = 0;
MOSI = 0;

GND = 0;
VDD = 1;
SW1 = 1;

SW2 = 1;
GREEN_LED = 0;
}

void timer2_init(void)
{
T2CON = 0x7f; // timer2 on and 16 pre, postscale
PR2 = 156; // 50hZ, 4m/4/16/16/50
pie1.TMR2IE = 1;
}

//void interrupt ISR_timer(void)
void interrupt (void)
{
// di();
unsigned char i;
if(TMR2IF)
{

	count_50hz++;
		if(count_50hz==20)  // REACH 1S
 		{
   			count_50hz=0;
   			Flag.reach_1s = 1;

 		}
 		else if(count_50hz == 5)
 		{
		Flag.reach_5hz = 1;
 		}

		PIR1.TMR2IF=0;
}

}

void power_on_delay(void)
{
unsigned int i;
for(i = 0; i<1000; i++)
{
delay_1ms();
}
}

void delay_200ms(void)
{
unsigned char j;
for(j = 0; j<40; j++)
{
delay_5ms();
}
}

void delay_50ms(void)
{
unsigned char j;
for(j = 0; j<50; j++)
{
delay_1ms();
}
}

/void delay_5ms(void)
{
unsigned char i;
for(i = 0; i<5; i++) // 85
5
{
delay_1ms;
}
}

Function: delay_1ms();

Description:

*********************************************************/
void delay_1ms(void)
{
unsigned char i;
for(i = 0; i<130; i++)
{
;
}
}

void delay_20us(void)
{
unsigned char i;
for(i = 0; i<3; i++)
{
;
}
}

void sub_program_1hz(void)
{
UINT8 i;
// UINT8 temp_buf[32];

if(Flag.reach_1s)
{
	Flag.reach_1s = 0;
for(i=0;i<19;i++)
	{
  temp_buf[i] = tx_buf[i];
}
	Send_Packet(W_TX_PAYLOAD_NOACK_CMD,temp_buf,19);
SwitchToRxMode();  //switch to Rx mode
}

}
void sub_program_2hz(void)
{
UINT8 i;
// UINT8 temp_buf[32];

if(Flag.reach_1s)
{
	Flag.reach_1s = 0;
for(i=0;i<19;i++)
	{
  temp_buf[i]=dx_buf[i];
}
	Send_Packet(W_TX_PAYLOAD_NOACK_CMD,temp_buf,19);
SwitchToRxMode();  //switch to Rx mode
}

}
void sub_program_3hz(void)
{
UINT8 i;
UINT8 temp_buf[32];

if(Flag.reach_1s)
{
	Flag.reach_1s = 0;
for(i=0;i<19;i++)
	{
  temp_buf[i]=cx_buf[i];
}
	Send_Packet(W_TX_PAYLOAD_NOACK_CMD,temp_buf,19);
SwitchToRxMode();  //switch to Rx mode
}

}

void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len)
{
UINT8 fifo_sta;

SwitchToTxMode();  //switch to tx mode

fifo_sta=SPI_Read_Reg(FIFO_STATUS);	// read register FIFO_STATUS's value
if((fifo_sta&FIFO_STATUS_TX_FULL)==0)//if not full, send data (write buff)
{
	SPI_Write_Buf(type, pbuf, len); // Writes data to buffer
bbb = 0;  //need for sleep
	delay_50ms();

}
}

void Receive_Packet(void)
{
UINT8 len,i,sta,fifo_sta,value,chksum,aa;
UINT8 rx_buf[MAX_PACKET_LEN];
GREEN_LED = 1;
sta=SPI_Read_Reg(STATUS); // read register STATUS's value
//usart_write(sta);
if((STATUS_RX_DR&sta) == 0x40) // if receive data ready (RX_DR) interrupt
{
do
{
len=SPI_Read_Reg(R_RX_PL_WID_CMD); // read len
//usart_write(0x41);
if(len<=MAX_PACKET_LEN)
{
SPI_Read_Buf(RD_RX_PLOAD,rx_buf,len);// read receive payload from RX_FIFO buffer
// usart_write(0x42);
}
else
{
SPI_Write_Reg(FLUSH_RX,0);//flush Rx
//usart_write(0x43);
}

		fifo_sta=SPI_Read_Reg(FIFO_STATUS);	// read register FIFO_STATUS's value
  //usart_write(fifo_sta);
	}while((fifo_sta&FIFO_STATUS_RX_EMPTY)==0); //while not empty

	chksum = 0;
   for(i=0;i<10;i++)      //ATENTIE
	{                      //ATENTIE
   EEprom_Write(i,rx_buf[i]);
   temp_buf[i] = Eeprom_Read(i);

// chksum +=rx_buf[i];
// usart_write(rx_buf[i]); //ATENTIE
}
// for(i=0;i<19;i++) ATENTIE
// { ATENTIE
// chksum +=rx_buf[i];
// usart_write(rx_buf[i]); ATENTIE
// } ATENTIE
// if(chksum==rx_buf[16]&&rx_buf[0]==0x30)
// {
// RED_LED = 1;
delay_50ms();
delay_50ms();
GREEN_LED = 0;
bbb = 0;
// chksum = porta
// INTCON = 0x48;
// CE = 0;
// IRQ = 0;
// confi = SPI_Read_Reg(CONFIG);
// SPI_Write_Reg(WRITE_REG | CONFIG, 0x00);
// chksum = porta;
// asm{
// SLEEP;
// NOP;
// }
// SPI_Write_Reg(WRITE_REG | CONFIG, confi);
//delay_50ms();
//delay_50ms();
}
SPI_Write_Reg(WRITE_REG|STATUS,sta);// clear RX_DR or TX_DS or MAX_RT interrupt flag
// INTCON = 0xC8;
// CE = 0;
// aa = portb;
// asm{
// SLEEP;
// NOP;
// }
}
void main()
{
unsigned char i, j, chksum;
// UINT8 temp_buf[32];
OSCCON = 0X70; // 8M crystal
WDTCON = 0X00;
OPTION_REG = 127;
init_mcu();
// WPUA = 0x30;
// init_comms();
power_on_delay();
// init_mcu();
ioca = 48;
count_50hz = 0;
Flag.reach_1s = 0;
// PCON = 63;
INTCON = 0xc0; // enable interrupt
RFM70_Initialize();
us = 't';
bbb = 0;
for(i=0;i<19;i++)
{
temp_buf[i] = Eeprom_Read(i);
}

while(1)
{
// if (Usart_Data_Ready()) ATENTIE
// { // If data is received ATENTIE
// us = Usart_Read(); ATENTIE // Read the received data
// USART_WRITE(us); ATENTIE
// } ATENTIE
if(bbb)
{
if (us=='t')
{
sub_program_1hz();
}
if (us=='d')
{
// Receive_Packet();
sub_program_2hz();
}
// if (us=='c')
// {
// sub_program_3hz();
// }
}
if(SW1==0)
{
us = 't';
bbb = 1;
// INTCON = 0x48;
// PIE1.RCIE = 1; USART INTERUPT
// CE = 0;
// asm {SLEEP;
// Nop;
}
if(SW2==0)
{
us = 'd';
bbb = 1;
}
// Receive_Packet();
// }
if(bbb==0)
{
INTCON = 0x48;
CE = 0;
// IRQ = 0;
confi = SPI_Read_Reg(CONFIG);
SPI_Write_Reg(WRITE_REG | CONFIG, 0x00);
// chksum = porta;
asm{
SLEEP;
// NOP;
}
}
SPI_Write_Reg(WRITE_REG | CONFIG, confi);
INTCON = 0xc0;
CE = 1;

}
}`

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

RFM70_receiver_code.zip
RFM70_transmiter_code.zip
register setup
I change rf_ch
I don't know if the addr is ok

void RF24::openWritingPipe(uint64_t value)
{
// Note that AVR 8-bit uC's store this LSB first, and the NRF24L01(+)
// expects it LSB first too, so we're good.

**
write_register(RX_ADDR_P0, reinterpret_cast<uint8_t
>(&value), addr_width);
write_register(TX_ADDR, reinterpret_cast<uint8_t
>(&value), addr_width);

//const uint8_t max_payload_size = 32;
//write_register(RX_PW_P0,rf24_min(payload_size,max_payload_size));
write_register(RX_PW_P0,payload_size);
}

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

`void Send_Packet(UINT8 type,UINT8* pbuf,UINT8 len)
{
UINT8 fifo_sta;
SwitchToTxMode(); //switch to tx mode

fifo_sta=SPI_Read_Reg(FIFO_STATUS); // read register FIFO_STATUS's value
if((fifo_sta&FIFO_STATUS_TX_FULL)==0)//if not full, send data (write buff)
{
SPI_Write_Buf(type, pbuf, len); // Writes data to buffer
bbb = 0; //need for sleep
delay_50ms();
}
}
that function for send from pic
that function use to send buf void sub_program_3hz(void)
{
UINT8 i;
UINT8 temp_buf[32];
if(Flag.reach_1s)
{
Flag.reach_1s = 0;
for(i=0;i<19;i++)
{
temp_buf[i]=cx_buf[i];
}
Send_Packet(W_TX_PAYLOAD_NOACK_CMD,temp_buf,19);
SwitchToRxMode(); //switch to Rx mode
}
}`

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

thanks
Merry Christmas and Happy new Year

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

for pic , mplab or mikroc compiler
work with anyone

@cjmcx
Copy link

cjmcx commented Dec 23, 2019

@TMRh20
Copy link
Member

TMRh20 commented Dec 24, 2019 via email

@cjmcx
Copy link

cjmcx commented Dec 24, 2019

all four are on Channel 6
pic rfm_init
{4,0xff},//auto retransmission dalay (4000us),auto retransmission count(15)
{5,0x06},//23 channel
{6,0x17},//air data rate-1M,out power 0dbm,setup LNA gain
esp32
radio.setChannel(0x06);
//radio.printDetails();
radio.startListening();
radio.printDetails();

@cjmcx
Copy link

cjmcx commented Dec 27, 2019

packet
can be diferit ?

@cjmcx
Copy link

cjmcx commented Dec 28, 2019

esp32
startFastWrite(buf,len,multicast);
pic16
spi_write_buf(type, pbuf, len);
does the sequence of orders sent to nrf24l01 matter, because it differs from esp32 to pic16

@cjmcx
Copy link

cjmcx commented Dec 29, 2019

it work !!!!

@cjmcx
Copy link

cjmcx commented Dec 29, 2019

but with another arduino library

@2bndy5 2bndy5 closed this as completed Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants