fix: i2c - stop() fix to wait for SCL to go HIGH (@olaf)

This commit is contained in:
Chris 2018-07-08 09:18:08 +02:00
parent defc7d9070
commit ba1ccf1994

View file

@ -170,6 +170,7 @@ bool I2C_WaitForSim() {
} }
// send i2c STOP // send i2c STOP
/*
void I2C_Stop(void) { void I2C_Stop(void) {
SCL_L; I2C_DELAY_2CLK; SCL_L; I2C_DELAY_2CLK;
SDA_L; I2C_DELAY_2CLK; SDA_L; I2C_DELAY_2CLK;
@ -180,7 +181,18 @@ void I2C_Stop(void) {
I2C_DELAY_2CLK; I2C_DELAY_2CLK;
I2C_DELAY_2CLK; I2C_DELAY_2CLK;
} }
*/
void I2C_Stop(void) {
SCL_L; I2C_DELAY_2CLK;
SDA_L; I2C_DELAY_2CLK;
SCL_H; I2C_DELAY_2CLK;
WaitSCL_H();
SDA_H;
I2C_DELAY_2CLK;
I2C_DELAY_2CLK;
I2C_DELAY_2CLK;
I2C_DELAY_2CLK;
}
// Send i2c ACK // Send i2c ACK
void I2C_Ack(void) { void I2C_Ack(void) {
SCL_L; I2C_DELAY_2CLK; SCL_L; I2C_DELAY_2CLK;
@ -256,7 +268,7 @@ uint8_t I2C_ReadByte(void) {
} }
// Sends one byte ( command to be written, SlaveDevice address) // Sends one byte ( command to be written, SlaveDevice address)
bool I2C_SendGETATR(uint8_t device_cmd, uint8_t device_address) { bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
bool bBreak = true; bool bBreak = true;
do { do {
if (!I2C_Start()) if (!I2C_Start())
@ -356,8 +368,9 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev
// len = uint8 (max buffer to read 256bytes) // len = uint8 (max buffer to read 256bytes)
uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address) { uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address) {
// extra wait 500us // extra wait 500us (514us measured)
SpinDelayUs(500); // 200us (xx measured)
SpinDelayUs(200);
bool bBreak = true; bool bBreak = true;
uint8_t readcount = 0; uint8_t readcount = 0;
@ -534,7 +547,7 @@ bool GetATR(smart_card_atr_t *card_ptr) {
// Send ATR // Send ATR
// start [C0 01] stop start C1 len aa bb cc stop] // start [C0 01] stop start C1 len aa bb cc stop]
I2C_SendGETATR(I2C_DEVICE_CMD_GENERATE_ATR, I2C_DEVICE_ADDRESS_MAIN); I2C_WriteCmd(I2C_DEVICE_CMD_GENERATE_ATR, I2C_DEVICE_ADDRESS_MAIN);
//wait for sim card to answer. //wait for sim card to answer.
if (!I2C_WaitForSim()) if (!I2C_WaitForSim())