Merge pull request #3412 from leptun/MK3_TWI_timeout
Hardware TWI timeout
This commit is contained in:
commit
eae6b4e911
4 changed files with 13 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "config.h"
|
||||
#include "fastio.h"
|
||||
#include "twi.h"
|
||||
#include "Timer.h"
|
||||
|
||||
|
||||
void twi_init(void)
|
||||
|
@ -44,6 +45,9 @@ void twi_init(void)
|
|||
|
||||
void twi_disable(void)
|
||||
{
|
||||
// disable TWI hardware.
|
||||
TWCR = 0;
|
||||
|
||||
// deactivate internal pullups for twi.
|
||||
WRITE(SDA_PIN, 0);
|
||||
WRITE(SCL_PIN, 0);
|
||||
|
@ -58,7 +62,13 @@ static void twi_stop()
|
|||
|
||||
static uint8_t twi_wait(uint8_t status)
|
||||
{
|
||||
while(!(TWCR & _BV(TWINT)));
|
||||
ShortTimer timmy;
|
||||
timmy.start();
|
||||
while(!(TWCR & _BV(TWINT))) {
|
||||
if (timmy.expired(TWI_TIMEOUT_MS)) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if(TW_STATUS != status)
|
||||
{
|
||||
twi_stop();
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue