@@ -72,18 +72,22 @@ void TwiMaster::Init() {
7272
7373TwiMaster::ErrorCodes TwiMaster::Read (uint8_t deviceAddress, uint8_t registerAddress, uint8_t * data, size_t size) {
7474 xSemaphoreTake (mutex, portMAX_DELAY);
75+ Wakeup ();
7576 auto ret = Write (deviceAddress, ®isterAddress, 1 , false );
7677 ret = Read (deviceAddress, data, size, true );
78+ Sleep ();
7779 xSemaphoreGive (mutex);
7880 return ret;
7981}
8082
8183TwiMaster::ErrorCodes TwiMaster::Write (uint8_t deviceAddress, uint8_t registerAddress, const uint8_t * data, size_t size) {
8284 ASSERT (size <= maxDataSize);
8385 xSemaphoreTake (mutex, portMAX_DELAY);
86+ Wakeup ();
8487 internalBuffer[0 ] = registerAddress;
8588 std::memcpy (internalBuffer + 1 , data, size);
8689 auto ret = Write (deviceAddress, internalBuffer, size + 1 , true );
90+ Sleep ();
8791 xSemaphoreGive (mutex);
8892 return ret;
8993}
@@ -179,13 +183,11 @@ void TwiMaster::Sleep() {
179183 }
180184 nrf_gpio_cfg_default (6 );
181185 nrf_gpio_cfg_default (7 );
182- NRF_LOG_INFO (" [TWIMASTER] Sleep" );
183186}
184187
185188void TwiMaster::Wakeup () {
186189 ConfigurePins ();
187190 twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
188- NRF_LOG_INFO (" [TWIMASTER] Wakeup" );
189191}
190192
191193/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
0 commit comments