Skip to content

Commit 6c96557

Browse files
authored
SAME54 MAC address reading (#289)
* Update atmel_start to latest Update weather_click to bme280 library * read MAC address from EEPROM for netxduo * Print mac address at boot Wait 30 second for DHCP timeout and print error rather than wait forever * output humidity and pressure data
1 parent e0275b0 commit 6c96557

38 files changed

+4710
-1036
lines changed

Microchip/ATSAME54-XPRO/app/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ set(SOURCES
88
azure_config.h
99
nx_client.c
1010
board_init.c
11-
console.c
1211
main.c
1312
)
1413

@@ -23,6 +22,7 @@ target_link_libraries(${PROJECT_NAME}
2322
app_common
2423
jsmn
2524
netxdriver
25+
bme280
2626
)
2727

2828
target_include_directories(${PROJECT_NAME}

Microchip/ATSAME54-XPRO/app/board_init.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,33 @@
33

44
#include "board_init.h"
55

6+
#include "weather_click.h"
7+
8+
#define CONF_AT24MAC_ADDRESS 0x5e
9+
10+
extern UCHAR _nx_driver_hardware_address[];
11+
12+
static void read_macaddress()
13+
{
14+
const uint8_t addr = 0x9A;
15+
16+
i2c_m_sync_enable(&I2C_AT24MAC);
17+
i2c_m_sync_set_slaveaddr(&I2C_AT24MAC, CONF_AT24MAC_ADDRESS, I2C_M_SEVEN);
18+
io_write(&(I2C_AT24MAC.io), &addr, 1);
19+
io_read(&(I2C_AT24MAC.io), _nx_driver_hardware_address, 6);
20+
}
21+
622
void board_init()
723
{
8-
/* Initializes MCU, drivers and middleware */
24+
// Initializes MCU, drivers and middleware
925
atmel_start_init();
10-
printf("Board initialized.\r\n");
1126

12-
WeatherClick_initialize();
13-
printf("Temperature sensor initialized.\r\n");
27+
// Load the MAC address from EEPROM into NetXDuo
28+
read_macaddress();
29+
30+
// Initialize Weather Click
31+
if (init_weather_click() != BME280_OK)
32+
{
33+
printf("FAILED to initialize weather click board\r\n");
34+
}
1435
}

Microchip/ATSAME54-XPRO/app/board_init.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "nx_api.h"
88

99
#include "atmel_start.h"
10-
#include "Bosch_BME280.h"
1110

1211
void board_init();
1312

Microchip/ATSAME54-XPRO/app/console.c

Lines changed: 0 additions & 48 deletions
This file was deleted.

Microchip/ATSAME54-XPRO/app/legacy/mqtt.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include <stdio.h>
77

8-
#include "Bosch_BME280.h"
98
#include "atmel_start.h"
9+
#include "weather_click.h"
1010

1111
#include "azure_iot_mqtt.h"
1212
#include "json_utils.h"
@@ -181,8 +181,12 @@ UINT azure_iot_mqtt_entry(NX_IP* ip_ptr, NX_PACKET_POOL* pool_ptr, NX_DNS* dns_p
181181

182182
#if __SENSOR_BME280__ == 1
183183
// Print the compensated temperature readings
184-
WeatherClick_waitforRead();
185-
temperature = Weather_getTemperatureDegC();
184+
struct bme280_data data;
185+
if (read_bme280(&data) != BME280_OK)
186+
{
187+
printf("FAILED to read weather click sensor\r\n");
188+
}
189+
temperature = data.temperature;
186190
#else
187191
temperature = 23.5;
188192
#endif

Microchip/ATSAME54-XPRO/app/nx_client.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include <stdio.h>
77

8-
#include "Bosch_BME280.h"
98
#include "atmel_start.h"
9+
#include "weather_click.h"
1010

1111
#include "nx_api.h"
1212
#include "nx_azure_iot_hub_client.h"
@@ -23,6 +23,8 @@
2323
#define IOT_MODEL_ID "dtmi:azurertos:devkit:gsg;2"
2424

2525
#define TELEMETRY_TEMPERATURE "temperature"
26+
#define TELEMETRY_PRESSURE "pressure"
27+
#define TELEMETRY_HUMIDITY "humidity"
2628
#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval"
2729
#define LED_STATE_PROPERTY "ledState"
2830
#define SET_LED_STATE_COMMAND "setLedState"
@@ -85,17 +87,28 @@ static UINT append_device_info_properties(NX_AZURE_IOT_JSON_WRITER* json_writer,
8587

8688
static UINT append_device_telemetry(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID* context)
8789
{
88-
float temperature;
90+
struct bme280_data data;
8991

9092
#if __SENSOR_BME280__ == 1
91-
WeatherClick_waitforRead();
92-
temperature = Weather_getTemperatureDegC();
93+
if (read_bme280(&data) != BME280_OK)
94+
{
95+
printf("FAILED to read weather click sensor\r\n");
96+
}
9397
#else
94-
temperature = 23.5;
98+
printf("Generating fake sensor data\r\n");
99+
data.temperature = 23.5;
100+
data.pressure = 1001245.76;
101+
data.humidity = 78.2;
95102
#endif
96103

97104
if (nx_azure_iot_json_writer_append_property_with_double_value(
98-
json_writer, (UCHAR*)TELEMETRY_TEMPERATURE, sizeof(TELEMETRY_TEMPERATURE) - 1, temperature, 2))
105+
json_writer, (UCHAR*)TELEMETRY_HUMIDITY, sizeof(TELEMETRY_HUMIDITY) - 1, data.humidity, 2) ||
106+
107+
nx_azure_iot_json_writer_append_property_with_double_value(
108+
json_writer, (UCHAR*)TELEMETRY_TEMPERATURE, sizeof(TELEMETRY_TEMPERATURE) - 1, data.temperature, 2) ||
109+
110+
nx_azure_iot_json_writer_append_property_with_double_value(
111+
json_writer, (UCHAR*)TELEMETRY_PRESSURE, sizeof(TELEMETRY_PRESSURE) - 1, data.pressure, 2))
99112
{
100113
return NX_NOT_SUCCESSFUL;
101114
}

Microchip/ATSAME54-XPRO/lib/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ add_subdirectory(${CORE_LIB_DIR}/netxduo netxduo)
1818
add_subdirectory(${CORE_LIB_DIR}/jsmn jsmn)
1919

2020
add_subdirectory(netx_driver)
21-
add_subdirectory(atmel_start)
21+
add_subdirectory(atmel_start)
22+
add_subdirectory(bme280)

Microchip/ATSAME54-XPRO/lib/atmel_start/CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ set(SOURCES
3232
src/hpl/ramecc/hpl_ramecc.c
3333
src/hpl/sercom/hpl_sercom.c
3434
src/stdio_redirect/stdio_io.c
35-
src/temperature_sensor/BME280_WeatherClick/Bosch_BME280.c
36-
src/temperature_sensor/temperature_sensor.c
3735
)
3836

37+
if(CMAKE_C_COMPILER_ID STREQUAL "IAR")
38+
list(APPEND SOURCES
39+
src/stdio_redirect/iar/read.c
40+
src/stdio_redirect/iar/write.c
41+
)
42+
else()
43+
list(APPEND SOURCES
44+
src/stdio_redirect/gcc/read.c
45+
src/stdio_redirect/gcc/write.c
46+
)
47+
endif()
48+
3949
add_library(${TARGET} OBJECT
4050
${SOURCES}
4151
)
@@ -45,6 +55,11 @@ target_compile_definitions(${TARGET}
4555
__SAME54P20A__
4656
)
4757

58+
target_compile_options(${TARGET}
59+
PRIVATE
60+
-Wno-error
61+
)
62+
4863
target_include_directories(${TARGET}
4964
PUBLIC
5065
config
@@ -68,8 +83,6 @@ target_include_directories(${TARGET}
6883
src/hri
6984
src/include
7085
src/stdio_redirect
71-
src/temperature_sensor
72-
src/temperature_sensor/BME280_WeatherClick
7386
)
7487

7588
target_link_libraries(${TARGET}

0 commit comments

Comments
 (0)