51 lines
1.6 KiB
C++
Executable File
51 lines
1.6 KiB
C++
Executable File
//
|
|
// Created by zong on 11/20/22.
|
|
//
|
|
#include <cstdio>
|
|
#include "bsp.h"
|
|
#include "prepherials.h"
|
|
|
|
int __io_putchar(int ch) {
|
|
return usart1.send((uint8_t *) &ch, 1);
|
|
}
|
|
|
|
int main() {
|
|
|
|
// basic_init();
|
|
system_init();
|
|
setup_prepherials();
|
|
pb.init(LED_BLUE_PIN); // PB7 ------> LED_BLUE
|
|
pe.init(9, AF, 1); // PE9 ------> TIM1_CH1
|
|
pa.init(USART1_TX_Pin, AF, 7); // PA9 ------> USART1_TX
|
|
pa.init(USART1_RX_Pin, AF, 7); // PA10 ------> USART1_RX
|
|
pg.init(13, AF, 4, OPEN_DRAIN, LL_PULLUP); // PG13 ------> I2C1_SDA
|
|
pg.init(14, AF, 4, OPEN_DRAIN, LL_PULLUP); // PG14 ------> I2C1_SCL
|
|
usart1.init(); // usart1 init_old
|
|
tim1.init_default();
|
|
tim1.set_pwm(CH1, 4, 4);
|
|
tim1.enable_output(CH1); // tim1 init_old
|
|
|
|
i2c1.i2c_init(&i2c_init_default); // i2c1 init_old
|
|
delay.delay_ms(10, true);
|
|
|
|
uint8_t data[2] = {0x00, 0x00};
|
|
|
|
while (1) {
|
|
// i2c_read_slave_reg(0x60, 0x0A, data, 1); // 0x26
|
|
// read 0x60 0x0A
|
|
data[0] = 0x0A;
|
|
i2c1.send_it_dep(0x60, data, 1, 10);
|
|
while (i2c1.state != I2C_STATE_WAIT);
|
|
// IF_ERROR_STUCK(i2c_read_block(i2c1_p, 0x60, 1, 10));
|
|
i2c1.read_block_dep(0x60, 1, 10);
|
|
while (i2c1.state != I2C_STATE_WAIT);
|
|
if (i2c1.recv_queue_dep.pop(data + 1) == HAL_OK) {
|
|
printf("0x60 0x0A: %x\n", data[1]);
|
|
}
|
|
delay.delay_ms(10, true);
|
|
if (i2c1.errors_dep)
|
|
while (1);
|
|
};
|
|
|
|
}
|