mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Update I2CBB.cpp
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
#define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
|
#define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
|
||||||
#define SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0)
|
#define SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0)
|
||||||
#define SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0)
|
#define SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0)
|
||||||
#define I2C_DELAY() {for(int xx=0;xx<1000;xx++){asm("nop");}}
|
#define I2C_DELAY() {for(int xx=0;xx<20;xx++){asm("nop");}}
|
||||||
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
|
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
|
||||||
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
|
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
|
||||||
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
|
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
|
||||||
@@ -34,10 +34,11 @@ void I2CBB::init() {
|
|||||||
unlock();
|
unlock();
|
||||||
unlock2();
|
unlock2();
|
||||||
//unstick bus
|
//unstick bus
|
||||||
for (int i = 0; i < 8; i++) {
|
// start();
|
||||||
read_bit();
|
// for (int i = 0; i < 8; i++) {
|
||||||
}
|
// read_bit();
|
||||||
stop();
|
// }
|
||||||
|
// stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2CBB::probe(uint8_t address) {
|
bool I2CBB::probe(uint8_t address) {
|
||||||
@@ -64,6 +65,9 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
|
|||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SCL_LOW();
|
||||||
|
I2C_DELAY();
|
||||||
|
// stop();
|
||||||
start();
|
start();
|
||||||
ack = send(DevAddress | 1);
|
ack = send(DevAddress | 1);
|
||||||
if (!ack) {
|
if (!ack) {
|
||||||
@@ -234,7 +238,7 @@ bool I2CBB::send(uint8_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDA_HIGH();
|
SDA_HIGH();
|
||||||
bool ack = read_bit() == 0;
|
bool ack = (read_bit() == 0);
|
||||||
return ack;
|
return ack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user