Renesas EK-RA2L1 and DA16200 WiFi shield.

The Renesas EK-RA2L1 is a development board for the Renesas R7FA2L1 MCU. It has an Arduino UNO compatible set of headers that fit the DA16200 WiFi Shield. Ironically the UNO cannot manage the DA16200 shield, but the MKR Arduin series can…but they have a different formfactor. Due to its very low power use it is excellent for battery fed IoT projects.

The following program lets the board read a DS18B20 and publish it to Thingspeak

#include "hal_data.h"
#include "r_uart_api.h"
#include "r_gpio_api.h"
#include "r_wdt_api.h"
#include "r_ioport_api.h"
#include "common_utils.h"

// WiFi credentials and ThingSpeak settings
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASSWORD "your_wifi_password"
#define THINGSPEAK_API_KEY "your_thingspeak_api_key"
#define THINGSPEAK_CHANNEL_ID "your_thingspeak_channel_id"

// DS18B20 GPIO pin
#define DS18B20_PIN IOPORT_PORT_01_PIN_04

// UART for DA16200
#define UART_CHANNEL 1

static uint8_t rx_buffer[128];
static uint8_t tx_buffer[128];

void uart_callback(uart_callback_args_t *p_args)
{
    // Handle UART events here
}

void setup_wifi()
{
    // Initialize UART for DA16200
    g_uart0.p_api->open(g_uart0.p_ctrl, g_uart0.p_cfg);

    // Connect to WiFi network
    sprintf(tx_buffer, "AT+CWJAP=\"%s\",\"%s\"\r\n", WIFI_SSID, WIFI_PASSWORD);
    g_uart0.p_api->write(g_uart0.p_ctrl, tx_buffer, strlen(tx_buffer));

    // Wait for response
    g_uart0.p_api->read(g_uart0.p_ctrl, rx_buffer, sizeof(rx_buffer));
    while (strstr(rx_buffer, "OK") == NULL);
}

float read_temperature()
{
    // Implement DS18B20 temperature reading
    // (Assume single-wire protocol library functions are available)
    ds18b20_start_conversion(DS18B20_PIN);
    R_BSP_SoftwareDelay(750, BSP_DELAY_UNITS_MILLISECONDS); // Wait for conversion

    float temperature = ds18b20_read_temperature(DS18B20_PIN);
    return temperature;
}

void send_to_thingspeak(float temperature)
{
    // Format the HTTP POST request
    sprintf(tx_buffer, "AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n");
    g_uart0.p_api->write(g_uart0.p_ctrl, tx_buffer, strlen(tx_buffer));
    g_uart0.p_api->read(g_uart0.p_ctrl, rx_buffer, sizeof(rx_buffer));
    while (strstr(rx_buffer, "OK") == NULL);

    sprintf(tx_buffer, "POST /update HTTP/1.1\r\nHost: api.thingspeak.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\napi_key=%s&field1=%.2f\r\n", 
            44 + strlen(THINGSPEAK_API_KEY), THINGSPEAK_API_KEY, temperature);
    g_uart0.p_api->write(g_uart0.p_ctrl, tx_buffer, strlen(tx_buffer));
    g_uart0.p_api->read(g_uart0.p_ctrl, rx_buffer, sizeof(rx_buffer));
}

int main(void)
{
    // Initialize board and peripherals
    bsp_leds_t leds = BSP_BOARD_LEDS;
    for (uint32_t i = 0; i < leds.led_count; i++)
    {
        g_ioport.p_api->pinWrite(leds.p_leds[i], BSP_IO_LEVEL_HIGH);
    }

    // Set up WiFi
    setup_wifi();

    while (1)
    {
        // Read temperature from DS18B20
        float temperature = read_temperature();

        // Send temperature to ThingSpeak
        send_to_thingspeak(temperature);

        // Wait for 15 seconds before sending the next data
        R_BSP_SoftwareDelay(15000, BSP_DELAY_UNITS_MILLISECONDS);
    }
}

void hal_entry(void)
{
    main();
}

void g_hal_init(void)
{
    g_common_init();
}

The libraries hal_data.h, r_uart_api.h, r_gpio_api.h, r_wdt_api.h, r_ioport_api.h, and common_utils.h are part of the Renesas Flexible Software Package (FSP) for Renesas RA family microcontrollers. The development environment for these libraries is typically e² studio or IAR Embedded Workbench for Renesas, which supports the Renesas RA microcontrollers and provides tools for configuring and programming the microcontroller peripherals.

Steps to Set Up the Development Environment

  1. Install e² studio:
    • Download and install e² studio from the Renesas website.
    • Ensure you have the latest version compatible with Renesas RA microcontrollers.
  2. Install FSP:
    • Download the Renesas Flexible Software Package (FSP) from the Renesas website.
    • Install FSP, which includes the HAL (Hardware Abstraction Layer) drivers and other utilities.
  3. Create a New Project:
    • Open e² studio.
    • Create a new project for the EK-RA21L board.
    • Select the appropriate RA microcontroller in the project setup.
  4. Configure the Project:
    • Use the FSP configurator in e² studio to configure the peripherals like UART, GPIO, WDT, and IOPORT.
    • This will generate the necessary configuration files, including hal_data.h.
  5. Add Source Files:
    • Add your application source files to the project.
    • Include the necessary headers like r_uart_api.h, r_gpio_api.h, r_wdt_api.h, r_ioport_api.h, and common_utils.h.
  6. Build and Debug:
    • Build the project using e² studio.
    • Debug the project using the on-board debugger or an external JTAG/SWD debugger.

In a follow up I will be discussing this board a bit more

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.