RFM73 C SPI library

warwound
Posts: 5
Joined: Fri Aug 23, 2019 9:06 am

RFM73 C SPI library

Postby warwound » Wed Aug 07, 2024 11:30 am

I am developing a C application using Eclipse and the ESP-IDF.
I have a WT32-ETH01 dev board with an RFM73 radio transceiver attached, I need help using the RFM73 from my C code.

There are various working C++ class based libraries for the RFM73 - both arduino and ESP-IDF.
But my application is a C application.
The RFM73 is quite old and many links for documentation/datasheets/examples are now dead.
I downloaded the RFM73 C library from www.voti.nl using the 'wayback machine':
http://web.archive.org/web/201501032126 ... :80/rfm73/

RFM73 C library contains rf73.h and rfm73.c and is "not adapted for a specific platform".
It requires me to create rf73-config.h and in that file define some macros: "you must provide an rfm73-config.h file that declares macro's that initialize and access the I/O pins, and for delaying a specified number of microseconds and milliseconds".

I also downloaded the 'C library adapted for DB038', this contains a rf73-config.h for the PIC platform:

Code: Select all

#define RFM70_SCK( x )   PIN_COPY( PORTC, 0, (x) ) 
#define RFM70_MOSI( x )  PIN_COPY( PORTC, 1, (x) )
#define RFM70_MISO       ( RC2 )
#define RFM70_CSN( x )   PIN_COPY( PORTC, 3, (x) )
#define RFM70_CE( x )    PIN_COPY( PORTC, 4, (x) )

#define RFM70_PIN_DIRECTION { \
   TRISC0 = 0; \
   TRISC1 = 0; \
   TRISC2 = 1; \
   TRISC3 = 0; \
   TRISC4 = 0; \
}

#define RFM70_WAIT_US( x ) WAIT_US( x )
#define RFM70_WAIT_MS( x ) wait_ms( x )
So I need to define similar same macros for my WT32-ETH01, and have tried:
rfm73-config.h

Code: Select all

//  standard SPI pins not available on wt32, need to use non standard pins
#define PIN_RFM73_CE GPIO_NUM_5
#define PIN_RFM73_CSN GPIO_NUM_17
#define PIN_RFM73_MISO GPIO_NUM_2
#define PIN_RFM73_MOSI GPIO_NUM_15
#define PIN_RFM73_SCK GPIO_NUM_14

#define RFM73_CE(pin_state) gpio_set_level(PIN_RFM73_CE, pin_state)

#define RFM73_CSN(pin_state) gpio_set_level(PIN_RFM73_CSN, pin_state)

#define RFM73_MISO gpio_get_level(PIN_RFM73_MISO)

#define RFM73_MOSI(pin_state) gpio_set_level(PIN_RFM73_MOSI, pin_state)

#define RFM73_PIN_DIRECTION rfm73_config_init()

#define RFM73_SCK(pin_state) gpio_set_level(PIN_RFM73_SCK, pin_state)

#define RFM73_WAIT_MS(period_millis) vTaskDelay(period_millis/portTICK_PERIOD_MS)

#define RFM73_WAIT_US(period_micros) vTaskDelay((period_micros*1000) / portTICK_PERIOD_MS)

void rfm73_config_init();
void rfm73_config_init_gpio(gpio_mode_t mode, uint64_t bit_mask, gpio_pulldown_t pulldown, gpio_pulldown_t pullup);
rfm73-config.c

Code: Select all

#include <rfm73-config.h>

void rfm73_config_init(){
	rfm73_config_init_gpio(GPIO_MODE_INPUT, (1ULL<<PIN_RFM73_MISO), 0, 0);
    rfm73_config_init_gpio(GPIO_MODE_OUTPUT, ((1ULL<<PIN_RFM73_MOSI) | (1ULL<<PIN_RFM73_SCK)), 0, 0);
    rfm73_config_init_gpio(GPIO_MODE_OUTPUT, ((1ULL<<PIN_RFM73_CE) | (1ULL<<PIN_RFM73_CSN)), 0, 1);
}

void rfm73_config_init_gpio(gpio_mode_t mode, uint64_t bit_mask, gpio_pulldown_t pulldown, gpio_pulldown_t pullup){
	gpio_config_t gpio_config_1={};
    gpio_config_1.intr_type = GPIO_INTR_DISABLE;
    gpio_config_1.mode = mode;
    gpio_config_1.pin_bit_mask = bit_mask;
    gpio_config_1.pull_down_en = pulldown;
    gpio_config_1.pull_up_en = pullup;
    //configure GPIO with the given settings
    ESP_ERROR_CHECK(gpio_config(&gpio_config_1));
}
I've tried with pins CE and CSN floating, and as in the above code pulled up.
My code fails and the rfm73.c code hangs when calling this method:

Code: Select all

void rfm73_register_write( unsigned char reg, unsigned char value ){
   if( reg < RFM73_CMD_WRITE_REG ){
      reg |= RFM73_CMD_WRITE_REG;      
   }  
   RFM73_CSN( 0 );                // CSN low, init SPI transaction
   (void)rfm73_SPI_RW( reg );    // select register
   (void)rfm73_SPI_RW( value );  // ..and write value to it..
   RFM73_CSN( 1 );                // CSN high again
}
Is the library trying to bitbang instead of using an SPI library/API?
Isn't the SCK pin meant to output a clock signal, nowhere do I see that.
Instead the SCK pin is either set high or low.


Can anyone suggest what my rfm73-config.h should contain for my WT32-ETH01?
Can I use the ESP-IDF SPI Master Driver instead of bitbanging?

Thanks for any and all help on this one!

Who is online

Users browsing this forum: Majestic-12 [Bot] and 350 guests