diff --git a/nametag8_V003/user/ch32v00x_it.c b/nametag8_V003/user/ch32v00x_it.c index 8b29546..d3b2240 100644 --- a/nametag8_V003/user/ch32v00x_it.c +++ b/nametag8_V003/user/ch32v00x_it.c @@ -31,6 +31,7 @@ void HardFault_Handler(void) while (1); } +__attribute__((interrupt("WCH-Interrupt-fast"))) void SysTick_Handler(void) { // ---- PROCESS UI AND COMMS diff --git a/nametag8_V003/user/i2c_slave.c b/nametag8_V003/user/i2c_slave.c index 8ff8b59..8a05747 100644 --- a/nametag8_V003/user/i2c_slave.c +++ b/nametag8_V003/user/i2c_slave.c @@ -9,7 +9,8 @@ * some notes: * - writing does not loop; if writing to the end then new writes will cause an error interrupt. * - added write protection for first 16 bytes. - * - many registers will only commit to action upon valid I2C stop received. + * - the code don't send NACKs on invalid writes. + * - write registers will only commit to action upon valid I2C stop received. * * * register map: @@ -129,8 +130,8 @@ void i2cs_write_cb(uint16_t initial_reg, uint16_t last_reg) // error - see i2c_slave.h for error types void i2cs_werr_cb(uint16_t reg, uint8_t data, uint8_t error) { - i2cs_reg[0x0d]++; - if (!i2cs_reg[0x0d]) i2cs_reg[0x0c]++; + i2cs_reg[REG_WERR_LO]++; + if (!i2cs_reg[REG_WERR_LO]) i2cs_reg[REG_WERR_HI]++; } // called upon every register read @@ -208,7 +209,7 @@ void I2C1_EV_IRQHandler(void) i2cs_state.position = i2cs_state.offset; // Reset position } - if (STAR1 & I2C_STAR1_RXNE) { // Write event + if (STAR1 & I2C_STAR1_RXNE) { // Write from master event if (i2cs_state.first_write == 2) { // low address byte written; set the offset i2cs_state.offset = i2cs_state.offset | I2C1->DATAR; i2cs_state.position = i2cs_state.offset; @@ -240,7 +241,7 @@ void I2C1_EV_IRQHandler(void) } } - if (STAR1 & I2C_STAR1_TXE) { // Read event + if (STAR1 & I2C_STAR1_TXE) { // Read to master event i2cs_state.writing = 0; if (i2cs_state.position < i2cs_state.reg_len) { I2C1->DATAR = i2cs_state.reg_file[i2cs_state.position]; @@ -262,6 +263,7 @@ void I2C1_EV_IRQHandler(void) } } +__attribute__((interrupt("WCH-Interrupt-fast"))) void I2C1_ER_IRQHandler(void) { uint16_t STAR1 = I2C1->STAR1; diff --git a/nametag8_V003/user/main.c b/nametag8_V003/user/main.c index 84f62ef..3f3a7b8 100644 --- a/nametag8_V003/user/main.c +++ b/nametag8_V003/user/main.c @@ -140,6 +140,7 @@ int main(void) exti_nvic_init(); // configure systick + systick_init(); while (1) { __WFI();