Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 4 months ago.
[F429ZI+AT86RF233] Thread communication lost after deepsleep
Hello!
I've been recently fighting with some issue. I am building application on mbed os for thread communication using Nucleo_F429ZI and AT86RF233 radio. My device is configured as thread sleepy end device. The idea is to read some measurements, send them via Thread network and put microcontroller to deepsleep. RTC generates wakeup interrupts. The problem is about sending packages of data. Everything is going in proper way when i put an endless loop between interrupts. But when i'm trying to put deepsleep() after data sending - nothing happens. I'm receiving nothing in UDP terminal on my PC. Another issue is that sleep() function doesn't work at all. I've been measuring power consumption during callig sleep() but there is no difference, Here is my code:
Thread communication
#include "mbed.h" #include "rtos.h" #include "NanostackInterface.h" #include "mbed-trace/mbed_trace.h" #include "socket_example.h" #include "common_functions.h" #include "ip6string.h" #include "socket_api.h" #include "UDPSocket.h" #include "sensors/SensorCollection.h" #include "rtc_api_hal.h" #include "mbed_sleep.h" #include "mbed_events.h" #include "rtos_idle.h" void trace_printer(const char* str) { printf("%s\n", str); } #define ATMEL 1 #define MCR20 2 #define NCS36510 3 #define MESH_LOWPAN 3 #define MESH_THREAD 4 #if MBED_CONF_APP_RADIO_TYPE == ATMEL #include "NanostackRfPhyAtmel.h" NanostackRfPhyAtmel rf_phy(ATMEL_SPI_MOSI, ATMEL_SPI_MISO, ATMEL_SPI_SCLK, ATMEL_SPI_CS, ATMEL_SPI_RST, ATMEL_SPI_SLP, ATMEL_SPI_IRQ, ATMEL_I2C_SDA, ATMEL_I2C_SCL); #elif MBED_CONF_APP_RADIO_TYPE == MCR20 #include "NanostackRfPhyMcr20a.h" NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, MCR20A_SPI_CS, MCR20A_SPI_RST, MCR20A_SPI_IRQ); #elif MBED_CONF_APP_RADIO_TYPE == NCS36510 #include "NanostackRfPhyNcs36510.h" NanostackRfPhyNcs36510 rf_phy; #endif //MBED_CONF_APP_RADIO_TYPE #if MBED_CONF_APP_MESH_TYPE == MESH_LOWPAN LoWPANNDInterface mesh; #elif MBED_CONF_APP_MESH_TYPE == MESH_THREAD ThreadInterface mesh; #endif //MBED_CONF_APP_MESH_TYPE //RTC setup time_t tim = 1497447150; //seconds from 1 january 1970 uint32_t wkup_delay = 15; //wakeup period in seconds from 1s to 36h //Sensors setup I2C i2c2(PF_0,PF_1); //pf0=d68 - i2c B sda , pf1=d69 - i2c B scl SensorCollection sensors(i2c2); // Setup UDP socket NetworkInterface * network_interface; UDPSocket sock; uint16_t portUDP = 12500; int ret = 0; SocketAddress serv_addr(".....",portUDP); //my comp Thread readout(osPriorityRealtime); #define RDT_SIG 0x20 InterruptIn button(PC_13); //README //uC is in deepsleep waiting for 2 IRQ //RTC wakeup and irq (pin PD_15) from radio //RTC irq -> readout -> sleep //radio irq -> some maintenance action with rf -> sleep void rtc_handler(void){ readout.signal_set(RDT_SIG); } void rtc_initialization(){ rtc_init(); rtc_write(tim); rtc_set_wake_up_timer(wkup_delay); rtc_set_irq_handler((uint32_t)rtc_handler); //setup handler for irq } void socket_initialization(NetworkInterface * interface){ network_interface = interface; sock.open(network_interface); sock.bind(serv_addr); } void readout_thread(){ while(true){ Thread::signal_wait(RDT_SIG); printf("WAKEUP!, timestamp: %lu \n", rtc_read()); printf("Sensors readout \n"); sensors.SensorCollectionReadout(); ret = sock.sendto(serv_addr, sensors.json_buffer, strlen(sensors.json_buffer)); if (ret <= 0){ printf("Error with socket sendto: %i\n", ret); } deepsleep(); //DEEPSLEEP CALL } } int main() { mbed_trace_init(); //start mesh iterface mbed_trace_print_function_set(trace_printer); printf("\n\nConnecting...\n"); mesh.initialize(&rf_phy); if(mesh.connect()){ printf("Connection failed!\n"); } while (NULL == mesh.get_ip_address()) Thread::wait(500); printf("connected. IP = %s\n", mesh.get_ip_address()); printf("MAC = %s\n", mesh.get_mac_address()); sensors.SetRtcTime(0x30,0x42,0x8,0x04,0x29,0x06,0x17); //in BCD code socket_initialization(&mesh); readout.start(readout_thread); button.fall(rtc_handler); rtc_initialization(); readout.signal_set(RDT_SIG); }
Also I've tried to put a deepsleep() in rtos idle thread like this, to make sure that all scheduled threads could perform:
rtos
void idle_thread(){ deepleep(); } int main(void){ .. rtos_attach_idle_hook(idle_thread); .. }
but then microcontroller cannot be woken up from deepsleep.
How can I make communication possible in my low-power application? I have tried almost everything. I will be very grateful for help. Please, list me things to try in my program.
Best regards, Wojciech Rzepecki