|
|
|
|
|
|
|
|
//printf("NACK, f=%d, i=%d\n", port->MFSR & 0x07, i); |
|
|
//printf("NACK, f=%d, i=%d\n", port->MFSR & 0x07, i); |
|
|
// TODO: check that hardware really sends stop automatically |
|
|
// TODO: check that hardware really sends stop automatically |
|
|
port->MCR = LPI2C_MCR_MEN | LPI2C_MCR_RTF; // clear the FIFO |
|
|
port->MCR = LPI2C_MCR_MEN | LPI2C_MCR_RTF; // clear the FIFO |
|
|
|
|
|
// TODO: is always sending a stop the right way to recover? |
|
|
|
|
|
port->MTDR = LPI2C_MTDR_CMD_STOP; |
|
|
return 2; // NACK for address |
|
|
return 2; // NACK for address |
|
|
//return 3; // NACK for data TODO: how to discern addr from data? |
|
|
//return 3; // NACK for data TODO: how to discern addr from data? |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sendStop) { |
|
|
if (sendStop) { |
|
|
if (status & LPI2C_MSR_SDF) { |
|
|
if (status & LPI2C_MSR_SDF) { |
|
|
//printf("stop sent, msr=%x\n", status); |
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
// master automatically sends stop condition on some |
|
|
|
|
|
// types of errors, so this flag only means success |
|
|
|
|
|
// when all comments in fifo have been fully used |
|
|
|
|
|
uint32_t fifo = port->MFSR & 0x07; |
|
|
|
|
|
if (fifo == 0) return 0; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
uint32_t fifo_used = port->MFSR & 0x07; // pg 2914 |
|
|
uint32_t fifo_used = port->MFSR & 0x07; // pg 2914 |