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.

Wireless Communication nRF24l01

Status
Not open for further replies.

Ventran

Newbie level 2
Joined
Apr 11, 2017
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
19
Hello everyone,
I have a problem with my wireless sensor system based on ATMega32 (as receiver) and MSP430 LunchPad (as transceiver). I can receive frame but I can not send characters from MSP430 to AVR.

I using two different library for my nRF24l01+. I chosen the same channels and address.

WP_20171130_002.jpg data.png

Receiver code
Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
//#include "usart.h"
#include "SPI.h"
#include "nRF24L01.h"
#include "nRF24L01_memory_map.h"

#define USART_BAUDRATE 38400
#define BAUD_PRESCALE (((16000000UL / (USART_BAUDRATE * 16UL))) - 1)

#define LED_PIN (1<<PD7)

void USART_Init(void);
void USART_SendByte(uint8_t u8Data);
void USART_SendChar(char * str);

char buffer_out1[32];
void majne_funkcjon(void * nRF_RX_buff, uint8_t len);

int main(void) {

	DDRD |= LED_PIN;

	DDRC |= 0xFF;
	PORTC |= 0xFF;

//	init_USART(__UBRR);
	nRF_init();

	USART_Init();																	//Inicjalizacja interfejsu USART
	sei();

	register_nRF_RX_Event_Callback(majne_funkcjon);

#if TRYB == 1
	nRF_TX_Power_Up(); //Enable in transmit mode
#endif

#if TRYB == 2
	nRF_RX_Power_Up(); //Enable in receiving mode

#endif

	while (1) {

#if TRYB == 1

		nRF_SendDataToAir((uint8_t *) "RX!\r\n");

		if (buffer_out1[0] != 0) {
			memset(buffer_out1, 0, 32);
		}

		_delay_ms(1000);
#endif

#if TRYB == 2

		nRF_RX_EVENT();

#endif
	}
}

void majne_funkcjon(void * nRF_RX_buff, uint8_t len) {

	PORTD |= LED_PIN;

	char buffer_for_itoa[4] = { 0, 0, 0, 0 };
	itoa(len, buffer_for_itoa, 10);

	char tab[] = {"Buffer [len], [txt]: "};
	USART_SendChar(tab);
	USART_SendChar(buffer_for_itoa);
	USART_SendChar( ", " );
	USART_SendChar((char *) nRF_RX_buff);
	USART_SendChar( "\r\n" );
	//nRF_RX_Power_Up();

	//PORTD &= ~(LED_PIN);

//	ENTER_NEW;
//	usart_send_str("ODEBRANO BAJTOW: ");
//	usart_send_str(buffer_for_itoa);
//	ENTER_NEW;
//	usart_send_str( (char *) nRF_RX_buff );

}

void USART_Init(void) {
	// Set baud rate
	UBRRL = BAUD_PRESCALE; // Load lower 8-bits into the low byte of the UBRR register
	UBRRH = (BAUD_PRESCALE >> 8);
	/* Load upper 8-bits into the high byte of the UBRR register
	 Default frame format is 8 data bits, no parity, 1 stop bit
	 to change use UCSRC, see AVR datasheet*/

	// Enable receiver and transmitter and receive complete interrupt
	UCSRB = ((1 << TXEN) | (1 << RXEN) | (1 << RXCIE));
}

void USART_SendByte(uint8_t u8Data) {

	while (!( UCSRA & (1 << UDRE)));												
	UDR = u8Data;
}

void USART_SendChar(char * str) {

	for (int i = 0; i < strlen((const char*) str); i++) {
		USART_SendByte(str[i]);
	}
}

Transceiver code (src: https://github.com/spirilis/msprf24)
Code:
#include <msp430.h>
#include "msprf24.h"
#include "nrf_userconfig.h"
#include "stdint.h"

volatile unsigned int user;

int main()
{
    uint8_t addr[5];
    char buf[32] = { "ALA \r\n" };

    WDTCTL = WDTHOLD | WDTPW;
    DCOCTL = CALDCO_16MHZ;
    BCSCTL1 = CALBC1_16MHZ;
    BCSCTL2 = DIVS_1;  // SMCLK = DCOCLK/2
    // SPI (USCI) uses SMCLK, prefer SMCLK < 10MHz (SPI speed limit for nRF24 = 10MHz)

    // Red, Green LED used for status
    P1DIR |= 0x41;
    P1OUT &= ~0x41;

    user = 0xFE;

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC; // CRC enabled, 8-bit
    rf_addr_width = 5;
    rf_speed_power = RF24_SPEED_1MBPS | RF24_POWER_0DBM;
    rf_channel = 10;

    msprf24_init();  // All RX pipes closed by default
    msprf24_set_pipe_packetsize(0, 32);
    msprf24_open_pipe(0, 1); // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
    // Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
    // auto-ACKs.  This does not have to match the pipe# used on the RX side.

    // Transmit to 'AVR'
    msprf24_standby();
    user = msprf24_current_state();
    addr[0] = 0x45;
    addr[1] = 0x44;
    addr[2] = 0x43;
    addr[3] = 0x42;
    addr[4] = 0x41;
    w_tx_addr(addr);
    w_rx_addr(0, addr); // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node
                        // needs to listen to the TX addr on pipe#0 to receive them.

    while (1)
    {
        __delay_cycles(800000);
       /* if (buf[0] == '0')
        {
            buf[0] = '1';
            buf[1] = '0';
        }
        else
        {
            buf[0] = '0';
            buf[1] = '1';
        } */



        w_tx_payload(32, buf);
        msprf24_activate_tx();
        LPM4;
/*
        if (rf_irq & RF24_IRQ_FLAGGED)
        {
            rf_irq &= ~RF24_IRQ_FLAGGED;

            msprf24_get_irq_reason();
            if (rf_irq & RF24_IRQ_TX)
            {
                P1OUT &= ~BIT0; // Red LED off
                P1OUT |= 0x40;  // Green LED on
            }
            if (rf_irq & RF24_IRQ_TXFAILED)
            {
                P1OUT &= ~BIT6; // Green LED off
                P1OUT |= BIT0;  // Red LED on
            }
        }*/
            msprf24_irq_clear(rf_irq);
            user = msprf24_get_last_retransmits();

    }
    return 0;
}
 

Attachments

  • WP_20171130_002.jpg
    WP_20171130_002.jpg
    501.4 KB · Views: 226

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top