TWI timeout

This commit is contained in:
Alex Voinea 2022-02-17 00:05:09 +01:00
parent 94eb60eade
commit 6351d29d70
4 changed files with 10 additions and 12 deletions

View File

@ -4,12 +4,6 @@
#include <inttypes.h>
#if defined(__cplusplus)
extern "C" {
#endif //defined(__cplusplus)
extern uint8_t pat9125_PID1;
extern uint8_t pat9125_PID2;
@ -24,9 +18,4 @@ extern uint8_t pat9125_update(void); // update all sensor data
extern uint8_t pat9125_update_y(void); // update _y only
extern uint8_t pat9125_update_bs(void); // update _b/_s only
#if defined(__cplusplus)
}
#endif //defined(__cplusplus)
#endif //PAT9125_H

View File

@ -24,6 +24,7 @@
#include "config.h"
#include "fastio.h"
#include "twi.h"
#include "Timer.h"
void twi_init(void)
@ -58,7 +59,13 @@ static void twi_stop()
static uint8_t twi_wait(uint8_t status)
{
while(!(TWCR & _BV(TWINT)));
static ShortTimer timmy;
timmy.start();
while(!(TWCR & _BV(TWINT))) {
if (timmy.expired(TWI_TIMEOUT_MS)) {
return 2;
}
}
if(TW_STATUS != status)
{
twi_stop();

View File

@ -26,6 +26,8 @@
#define TWI_FREQ 400000L
#endif
#define TWI_TIMEOUT_MS 100
/*
* Function twi_init
* Desc readys twi pins and sets twi bitrate