RAK15003 WisBlock 32kByte FRAM Module Quick Start Guide
Prerequisite
- Assemble the RAK15003 with a WisBlock Base and WisBlock Core by following the RAK15003 Installation Guide.
- Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
- USB Cable
- Li-Ion/LiPo Battery (optional)
- Solar Charger (optional)
Software Configuration and Example
-
This guide uses the RAK4631 WisBlock Core to demonstrate the configuration and upload process. The example is also compatible with other WisBlock Cores, including the RAK11200 and RAK11310.
-
When using the RAK11200 WisBlock WiFi Module, configure the BOOT0 pin properly before uploading the firmware. Incorrect BOOT0 configuration may cause the firmware upload to fail. For more information, refer to the RAK11200 Quick Start Guide.
-
Install the RAKwireless Arduino BSP's for WisBlock by using the
https://raw.githubusercontent.com/RAKwireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless_index.jsonboard installation package. The WisBlock Core should now be available on the Arduino IDE. -
After that, you need to select the WisBlock Core you have.
Figure 1: Selecting RAK4631 as WisBlock Core- Next, copy the following sample code into your Arduino IDE.
Click to view the code
/**
@file RAK1500x_FRAM_Read_Write_MB85RC.ino
@author rakwireless.com
@brief Test RAK1500x FRAM read and write functions.
Suitable for RAK15003, RAK15003, RAK15005.
@version 0.1
@date 2021-4-13
@copyright Copyright (c) 2022
**/
#include "RAK1500x_MB85RC.h" // Click here to get the library: http://librarymanager/All#RAK1500x_MB85RC
#define DEV_ADDR MB85RC_DEV_ADDRESS
/*
* @note If installed in SlotB.
* Since IO2 is the power supply enable pin level is high.
* Only read operation can be performed on this slot.
*/
#define WP_PING WB_IO1 // SlotA installation.
//#define WP_PING WB_IO3 // SlotC installation.
//#define WP_PING WB_IO5 // SlotD installation.
RAK_MB85RC MB85RC;
void setup()
{
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
pinMode(WP_PING, OUTPUT);
digitalWrite(WP_PING, LOW);
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Wire.begin();
while(MB85RC.begin(Wire , DEV_ADDR) == false)
{
Serial.println("MB85RC is not connected.");
while(1)
{
delay(1000);
}
}
switch (MB85RC.getDeviceType())
{
case MB85RC256:
Serial.print("RAK15003(MB85RC256) ");
break;
case MB85RC512:
Serial.print("RAK15003(MB85RC512) ");
break;
case MB85RC1:
Serial.print("RAK15005(MB85RC1M) ");
break;
default:
break;
}
Serial.println("initialized successfully.");
}
void loop()
{
char writeDate[20]="Hello RAK1500X.";
char readDate[20] = {0};
Serial.println("Simple reading and writing test.");
MB85RC.write(0x0000, (uint8_t*)writeDate , strlen(writeDate));
MB85RC.read( 0x0000, (uint8_t*)readDate , strlen(writeDate));
Serial.println(readDate);
Serial.println("Comparing whether the read and write content is consistent.");
readWriteTest();
Serial.println("Read the contents of the entire chip.");
readEntireChip();
Serial.println();
Serial.println("Do nothing here, just love you!");
while(1)
{
delay(100);
}
}
/*
* @brief Comparing whether the read and write content is consistent.
* Can be used to test the probability of FRAM read and write errors.
*/
void readWriteTest()
{
char writeBuf[16] = ">>Test RAK1500X";
char readBuf[16] = {0};
uint32_t successCount = 0;
uint32_t failCount = 0;
uint32_t productSize = MB85RC.getDeviceCapacity();
float progress = 0;
time_t interval = millis();
for(uint32_t i = 0; i < productSize; i+=sizeof(writeBuf))
{
MB85RC.write(i, (uint8_t*)writeBuf , sizeof(writeBuf));
MB85RC.read( i, (uint8_t*)readBuf , sizeof(readBuf));
if(memcmp(writeBuf , readBuf , sizeof(readBuf)) == 0)
{
successCount++;
}
else
{
failCount++;
}
if((millis() - interval) > 1000)
{
interval = millis();
Serial.printf("Test progress: %5.2f%% , successCount: %ld , failCount:%ld \n",progress,successCount,failCount);
}
progress = (float)(i+sizeof(writeBuf)) * 100 / productSize;
memset(readBuf , '0' , sizeof(readBuf));
delay(1);
}
Serial.printf("Test progress: %5.2f%% , successCount: %ld , failCount:%ld \n",progress,successCount,failCount);
}
/*
* @brief Read the contents of the entire chip.
*/
void readEntireChip()
{
char readBuf[32] = {0};
uint32_t productSize = MB85RC.getDeviceCapacity();
Serial.println();
for(uint32_t i = 0; i < productSize; i+=sizeof(readBuf))
{
MB85RC.read( i, (uint8_t*)readBuf , sizeof(readBuf));
Serial.print("0x");
Serial.print(i,HEX);
Serial.print("\t");
for(uint32_t j = 0; j < sizeof(readBuf); j++)
{
Serial.print("0x");
Serial.print(readBuf[j],HEX);
Serial.print(' ');
}
Serial.println();
}
}
If you experience any error in compiling the example sketch, check the updated code for your WisBlock Core Module. You can find it on the RAK15003 WisBlock Example Code Repository. The sample code on GitHub will work on all WisBlock Core.
- Once the example code is open, install the RAK1500x_MB85RC library. Click the highlighted link.
Figure 1: Accessing the library used for RAK15003 Module
Figure 1: Installing the compatible library for RAK15003 Module- After a successful library installation, select the right serial port and upload the code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the RAK15003 example code- When you have successfully uploaded the example sketch, you'll see that the WisBlock Core will perform a Write-Read test on the FRAM. Then, it reads out all its contents.
Figure 1: Uploading the RAK15003 example codeResources
For all WisBlock Core modules: FRAM Read/Write sample codes for RAK15003
