TWI timeout
This commit is contained in:
parent
94eb60eade
commit
6351d29d70
|
|
@ -4,12 +4,6 @@
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif //defined(__cplusplus)
|
|
||||||
|
|
||||||
|
|
||||||
extern uint8_t pat9125_PID1;
|
extern uint8_t pat9125_PID1;
|
||||||
extern uint8_t pat9125_PID2;
|
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_y(void); // update _y only
|
||||||
extern uint8_t pat9125_update_bs(void); // update _b/_s only
|
extern uint8_t pat9125_update_bs(void); // update _b/_s only
|
||||||
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif //defined(__cplusplus)
|
|
||||||
|
|
||||||
#endif //PAT9125_H
|
#endif //PAT9125_H
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "twi.h"
|
#include "twi.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
|
||||||
void twi_init(void)
|
void twi_init(void)
|
||||||
|
|
@ -58,7 +59,13 @@ static void twi_stop()
|
||||||
|
|
||||||
static uint8_t twi_wait(uint8_t status)
|
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)
|
if(TW_STATUS != status)
|
||||||
{
|
{
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#define TWI_FREQ 400000L
|
#define TWI_FREQ 400000L
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TWI_TIMEOUT_MS 100
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function twi_init
|
* Function twi_init
|
||||||
* Desc readys twi pins and sets twi bitrate
|
* Desc readys twi pins and sets twi bitrate
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue