diff --git a/workspace/TS100/Core/BSP/Miniware/BSP.cpp b/workspace/TS100/Core/BSP/Miniware/BSP.cpp index da79b46f..760c7afd 100644 --- a/workspace/TS100/Core/BSP/Miniware/BSP.cpp +++ b/workspace/TS100/Core/BSP/Miniware/BSP.cpp @@ -94,6 +94,9 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) { sum += samples[i]; sum /= BATTFILTERDEPTH; + if (divisor == 0) { + divisor = 1; + } return sum * 4 / divisor; } diff --git a/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp b/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp index 44db8cb2..1c561c77 100644 --- a/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp +++ b/workspace/TS100/Core/BSP/Miniware/I2CBB.cpp @@ -13,7 +13,7 @@ #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 SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0) -#define I2C_DELAY() HAL_Delay(1); +#define I2C_DELAY() {for(int xx=0;xx<100;xx++){asm("nop");}} void I2CBB::init() { //Set GPIO's to output open drain GPIO_InitTypeDef GPIO_InitStruct; @@ -70,6 +70,7 @@ bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, return false; } while (Size) { + resetWatchdog(); bool ack = send(pData[0]); if (!ack) { stop(); @@ -182,7 +183,7 @@ bool I2CBB::send(uint8_t value) { value <<= 1; } - bool ack = read_bit()==0; + bool ack = read_bit() == 0; return ack; } diff --git a/workspace/TS100/Core/Drivers/FUSB302/fusb302b.cpp b/workspace/TS100/Core/Drivers/FUSB302/fusb302b.cpp index 46956178..6e57b9fc 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/fusb302b.cpp +++ b/workspace/TS100/Core/Drivers/FUSB302/fusb302b.cpp @@ -152,14 +152,21 @@ void fusb_setup() { /* Flush the RX buffer */ fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH); + resetWatchdog(); /* Measure CC1 */ fusb_write_byte( FUSB_SWITCHES0, 0x07); - osDelay(1); + resetWatchdog(); + delay_ms(1); + resetWatchdog(); uint8_t cc1 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL; + resetWatchdog(); /* Measure CC2 */ + resetWatchdog(); fusb_write_byte( FUSB_SWITCHES0, 0x0B); - osDelay(1); + resetWatchdog(); + delay_ms(1); + resetWatchdog(); uint8_t cc2 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL; /* Select the correct CC line for BMC signaling; also enable AUTO_CRC */ @@ -170,6 +177,7 @@ void fusb_setup() { fusb_write_byte( FUSB_SWITCHES1, 0x26); fusb_write_byte( FUSB_SWITCHES0, 0x0B); } + resetWatchdog(); /* Reset the PD logic */ fusb_write_byte( FUSB_RESET, FUSB_RESET_PD_RESET); diff --git a/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h b/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h index 7bb4ed2c..d11979a9 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h +++ b/workspace/TS100/Core/Drivers/FUSB302/fusb302b.h @@ -24,10 +24,10 @@ #include /* I2C addresses of the FUSB302B chips */ -#define FUSB302B_ADDR 0x22 -#define FUSB302B01_ADDR 0x23 -#define FUSB302B10_ADDR 0x24 -#define FUSB302B11_ADDR 0x25 +#define FUSB302B_ADDR (0x22<<1) +#define FUSB302B01_ADDR (0x23<<1) +#define FUSB302B10_ADDR (0x24<<1) +#define FUSB302B11_ADDR (0x25<<1) /* Device ID register */ #define FUSB_DEVICE_ID 0x01