[Oberon] FPGA - nRF24L01 connection

Tomas Kral thomas.kral at email.cz
Sat Apr 14 10:20:45 CEST 2018


On Fri, 13 Apr 2018 10:46:11 +0300
Jörg <joerg.straube at iaeth.ch> wrote:

> The easiest is to only use pipe 0.
Hi,

I worked out a simple code from `rpi-hub.cpp' modified to use only
pipe-0 for reading/writing. Attached, if you wished to follow, as I'd
learn about experience on your systems.

On Oberon end, I just execute `Ping' procedure, that in return calls
`Pong'. Outbound 90% loss, inboud 10% loss.

This makes me curious how to manage RPI reliable network time server,
file server, etc.

/*  Filename : rpi-hub.cpp
 *
 *  Author : Stanley Seow
 *  e-mail : stanleyseow at gmail.com
 *  date   : 6th Mar 2013
 *
 * 03/17/2013 : Charles-Henri Hallard (http://hallard.me)
 *    Changed to use modified bcm2835 and RF24 library 
 * 14.04.2018 : [tcat] thomas.kral at email.cz
 *    Adapted for RISC-5 Oberon `SCC.Mod'
 */

#include <cstdlib>
#include <iostream>
#include <RF24/RF24.h>

using namespace std;

// Default pipe addresses after radio reset
const uint64_t pipes[6] = {
          0xe7e7e7e7e7LL, 0xc2c2c2c2c2LL,
          0xc3, 0xc4, 0xc5, 0xc6 
  };

// CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); 


int main(int argc, char** argv) 
{
  uint8_t len;

  // Default radio setting
  radio.begin();
  radio.setRetries(50,50);
  radio.setChannel(5);
  radio.maskIRQ(1,1,1);

  // Enable pipe-0 for reading and writing
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(0,pipes[0]);

  // Start listening
  // Dump radio configuration for debugging
  radio.startListening();
  radio.printDetails();
  
  printf("Output below [Ctrl-C to exit]: \n");
  delay(1);
  
  while(true)
  {
    char receivePayload[32];
    uint8_t pipe = 0;
    
    // Start listening
    radio.startListening();
          
    if ( radio.available(&pipe) ) 
    {

      // Read payload 32 bytes from Oberon
      len = 32;
      radio.read( receivePayload, len );
      len = strlen(receivePayload);

      // Display it on screen
      printf("Recv: size=%i payload=%s
      pipe=%i\n",len,receivePayload,pipe);

      // Return payload back, stamped with 'x'
      radio.stopListening();
      receivePayload[len-1]='x';
      radio.write(receivePayload,len);
      printf("Send: size=%i payload=%s
      pipe:%i\n",len,receivePayload,pipe); }

    // delayMicroseconds(20); /* 100% of CPU */
    delay(1); /* 15% of CPU */
  }
  return 0;
}

-- 
Tomas Kral <thomas.kral at email.cz>


More information about the Oberon mailing list