nop();
break;
case ACCELEROMETER_STPIFG:
+ nop();
break;
case ACCELEROMETER_RXIFG:
if (LengthCount > 0) {
void mw_acc_i2c_write(uint8_t RegisterAddress, uint8_t *pData, uint8_t Length)
{
+ int tmo;
+
if (Length == 0 || pData == 0)
return;
ACCELEROMETER_IE |= UCTXIE;
ACCELEROMETER_TXBUF = RegisterAddress;
- while (AccelerometerBusy)
- nop();
+ tmo = 0;
+ while (AccelerometerBusy) {
+ while (tmo++ < 1000)
+ __delay_cycles(16000);
+ if (tmo >= 1000) {
+ debug_uart_tx("ACC I2C tx tmo\n");
+ return;
+ }
+ }
while (ACCELEROMETER_CTL1 & UCTXSTP)
nop();
* received. If this is interrupted an extra byte may be read.
* however, it will be discarded during the next read
*/
- if ( LengthCount == 1 ) {
+ if (LengthCount == 1) {
/* errata usci30: prevent interruption of sending stop
* so that only one byte is read
* this requires 62 us @ 320 kHz, 51 @ 400 kHz
*/
+ __disable_interrupt();
+
ACCELEROMETER_CTL1 |= UCTXSTT;
while(ACCELEROMETER_CTL1 & UCTXSTT)
nop();
ACCELEROMETER_CTL1 |= UCTXSTP;
+
+ __enable_interrupt();
} else {
ACCELEROMETER_CTL1 |= UCTXSTT;
}
char tstr[16];
#endif
+ // it takes at least 20ms to power up
ENABLE_ACCELEROMETER_POWER();
+ __delay_cycles(320000);
mw_acc_init_i2c();
ACCELEROMETER_INT_DISABLE();
mw_acc_disable_i2c();
- DISABLE_ACCELEROMETER_POWER();
+ /// DISABLE_ACCELEROMETER_POWER();
AccelState = ACCEL_STATE_DISABLED;
}
}