6 years, 11 months ago.

Do you have any library for receiver and transmitter for arm mbed?

I'm using these two modules (https://sites.google.com/site/summerfuelrobots/arduino-sensor-tutorials/rf-wireless-transmitter-receiver-module-433mhz-for-arduino)

1 Answer

6 years, 11 months ago.

Hello Alan,

You can try to use the Manchester encoding library to drive the modules. There is available a Transmitter demo and a Receiver demo you can start with. I would recommend to begin at speed reduced to 600 bps and to send a short message. Once the transfer is working you can try to increase the speed and add more payload data step by step. Make sure you use the same transfer speed and message data for both modules.
Import the demos and modify the main.cpp as below :

Transmitter

#include "mbed.h"
#include "Manchester.h"
#include "CRC16.h"

DigitalOut      led(LED1);
Manchester      man(PA_8, PA_9, 600);   // Tx pin, Rx pin (not connected), speed [bps]
ManchesterMsg   msg(255);               // Message container (max bytes)
CRC16           crc16;                  // CRC16 object

int main(void) {
    while(1) {
        msg.clear();                                // Clear the message
        //msg << "Hello World!" << 0xfa74c309;        // Add some data to the message
        msg << 0xfa;                                // Add some data to the message
        msg << crc16.calc(msg.data, msg.len);       // Append CRC16 to the message
        man.transmit(msg);                          // Transmit the message
        wait_ms(1000);
        led = !led;
    }
}

Receiver

#include "mbed.h"
#include "Manchester.h"
#include "CRC16.h"

DigitalOut      led(LED1);
Manchester      man(PA_8, PA_9, 600);   // Tx pin (not connected), Rx pin, speed [bps]
ManchesterMsg   msg(100);               // Message container (max bytes)
//char            str[80];                // Storage for the received array of char
//uint32_t        val;                    // Storage for the value received
uint8_t         val;                    // Storage for the value received
CRC16           crc16;                  // CRC16 object
unsigned short  recvCRC16;              // CRC16 received in the message
unsigned short  calcCRC16;              // CRC16 calculated

int main(void) {
    while(1) {
        if(man.receive(msg)) {      // Receive message
            
            // Print data length and raw data bytes
            printf("\r\n----------------------------------------\r\n");
            printf("Message length = %d, Raw data :\r\n", msg.len);
            for(size_t i = 0; i < msg.len; i++) {
                if((i + 1) % 10 == 0)
                    printf("  %.2x\r\n", msg.data[i]);
                else
                    printf("  %.2x", msg.data[i]);
            }
            printf("\r\n\r\n");
            
            // Calculate CRC16. Exclude CRC bytes (last two bytes) from calculation.
            calcCRC16 = crc16.calc(msg.data, msg.len - 2);            
            printf("Calculated CRC16 = %d\r\n", calcCRC16);
            
            // Extract data and CRC16 from the message
            //msg >> str >> val >> recvCRC16;
            msg >> val >> recvCRC16;
            
            printf("Received   CRC16 = %d\r\n", recvCRC16);
            printf("\r\n");           
 
            if( calcCRC16 == recvCRC16) {
                printf("Received data :\r\n");
                //printf("  str = %s\r\n", str);
                printf("  val = 0x%x\r\n", val);
            }
            else
                printf("CRC error\r\n");
        }
        else
            printf("Error\r\n");

        led = !led;
    }
}

Warning: Incompatible voltage levels!

Because your NUCLEO board is runing at 3.3V and the RF modules at 5V, a voltage level converter has to be included into the connection line from the ATAD pin on the Receiver module to the PA_9 pin on the NUCLEO board in order to avoid damaging the NUCLEO board ! If you operate the Transmitter module at 5V I would recommend to use a voltage level converter also for the connection line from the PA_8 pin on the NUCLEO board to the DATA pin on the Transmitter module to assure reliable operation.

NOTE: Some pins on NUCLEO boards are 5V tolerant. Have a look at for example here. The PA_9 pin on the NUCLEO-F103RB board supposed to be such. In that case the voltage converter from 5V to 3.3V can be ommitted. However, use it at your own risk. I'll take no responsibility whatsoever for any damages to your MBED board!

Wiring

When supplied from 3.3V source:

NUCLEO-F103RBTransmitter module
GND->GND
+3.3V->VCC
PA_8->DATA

When supplied from 5V source:

NUCLEO-F103RBTransmitter module
GND->GND
+5V->VCC
PA_8-> Voltage level converter from 3.3V to 5V ->DATA

Supplied only from 5V source:

Receiver moduleNUCLEO-F103RB
GND<-GND
VCC<-+5V
ATAD-> Voltage level converter from 5V to 3.3V ->PA_9

With best regards,

Zoltan

Accepted Answer

Thanks for the help, it will be very useful for me.

posted by Alan Silva 29 Jan 2018