-
gd32f350R 使用iic1 sos
使用GD32F350R系列的开发板,调试iic协议,使用iic0的时候两个开发板可以通信(都使用iic0接口,一个主,一个从),但是换成iic1就不可以了,不论iic1做主机还是从机都不行。iic1做主机时发现在i2c_master_addressing之后,抓出来的波形只有一个start信号,并没有从机地址的信号发出来[font=Consolas, Courier New, monospace]以下是主机程序:[/font] [backcolor=rgb(255, 255, 255)][font=Consolas, "][color=#808080]#include[/color][color=#0000ff] [/color][color=#a31515]
[/color] [color=#808080]#include[/color][color=#0000ff] [/color][color=#a31515]"gd32f3x0.h"[/color] [color=#808080]#include[/color][color=#0000ff] [/color][color=#a31515]"gd32f350r_eval.h"[/color] [color=#808080]#define[/color][color=#0000ff] [/color][color=#bd63c5]I2C1_OWN_ADDRESS7[/color][color=#0000ff] [/color][color=#09885a]0x[/color]72 [color=#808080]#define[/color][color=#0000ff] [/color][color=#bd63c5]I2C1_SLAVE_ADDRESS7[/color][color=#0000ff] [/color][color=#09885a]0x[/color]45 [color=#0000ff]uint8_t[/color] i2c_transmitter[16]; [color=#0000ff]void[/color] rcu_config([color=#0000ff]void[/color]); [color=#0000ff]void[/color] gpio_config([color=#0000ff]void[/color]); [color=#0000ff]void[/color] i2c_config([color=#0000ff]void[/color]); [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] main function[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]int[/color] main([color=#0000ff]void[/color]) { [color=#0000ff]int[/color] i; gd_eval_com_init([color=#bd63c5]EVAL_COM[/color]); [color=#008000] /* RCU configure */[/color] rcu_config(); [color=#008000] /* GPIO configure */[/color] gpio_config(); [color=#008000] /* I2C configure */[/color] i2c_config(); [color=#0000ff]for[/color](i = 0; i < 16; i++) { i2c_transmitter[i] = i + [color=#09885a]0x[/color]80; } [color=#008000] /* wait until I2C bus is idle */[/color] [color=#0000ff]while[/color](i2c_flag_get(I2C1, I2C_FLAG_I2CBSY)); [color=#008000] /* send a start condition to I2C bus */[/color] i2c_start_on_bus(I2C1); [color=#008000] /* wait until SBSEND bit is set */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C1, I2C_FLAG_SBSEND)); [color=#008000] /* send slave address to I2C bus */[/color] i2c_master_addressing(I2C1, [color=#09885a]0x[/color]45, I2C_TRANSMITTER); [color=#008000] /* wait until ADDSEND bit is set */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C1, I2C_FLAG_ADDSEND)); [color=#008000] /* clear ADDSEND bit */[/color] i2c_flag_clear(I2C1, I2C_FLAG_ADDSEND); [color=#008000] /* wait until the transmit data buffer is empty */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C1, I2C_FLAG_TBE)); printf([color=#a31515]"start to transfer\r\n"[/color]); [color=#0000ff]for[/color](i = 0; i < 16; i++) { [color=#008000] /* data transmission */[/color] i2c_data_transmit(I2C1, i2c_transmitter[i]); [color=#008000] /* wait until the TBE bit is set */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C1, I2C_FLAG_TBE)); } [color=#008000] /* send a stop condition to I2C bus */[/color] i2c_stop_on_bus(I2C1); [color=#008000] /* wait until stop condition generate */[/color] [color=#0000ff]while[/color](I2C_CTL0(I2C1) & [color=#09885a]0x[/color]0200); [color=#008000] /* infinite loop */[/color] [color=#0000ff]while[/color](1) { } } [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] enable the peripheral clock[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]void[/color] rcu_config([color=#0000ff]void[/color]) { [color=#008000] /* enable GPIOB clock */[/color] rcu_periph_clock_enable(RCU_GPIOB); [color=#008000] /* enable I2C1 clock */[/color] rcu_periph_clock_enable(RCU_I2C1); } [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] configure the GPIO ports[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]void[/color] gpio_config([color=#0000ff]void[/color]) { [color=#008000] /* connect PB6 to I2C1_SCL */[/color] gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_10); [color=#008000] /* connect PB7 to I2C1_SDA */[/color] gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_11); [color=#008000] /* configure GPIO pins of I2C1 */[/color] gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10); gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_10); gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_11); gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_11); } [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] configure the I2C1 and I2C1 interfaces[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]void[/color] i2c_config([color=#0000ff]void[/color]) { [color=#008000] /* I2C clock configure */[/color] i2c_clock_config(I2C1, 100000, I2C_DTCY_2); [color=#008000] /* I2C address configure */[/color] i2c_mode_addr_config(I2C1, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, [color=#bd63c5]I2C1_SLAVE_ADDRESS7[/color]); [color=#008000] /* enable I2C1 */[/color] i2c_enable(I2C1); [color=#008000] /* enable acknowledge */[/color] i2c_ack_config(I2C1, I2C_ACK_ENABLE); } [color=#008000]/* retarget the C library printf function to the USART */[/color] [color=#0000ff]int[/color] fputc([color=#0000ff]int[/color] [color=#808080]ch[/color], FILE *[color=#808080]f[/color]) { usart_data_transmit([color=#bd63c5]EVAL_COM[/color], ([color=#0000ff]uint8_t[/color]) ch); [color=#0000ff]while[/color]([color=#2f4f4f]RESET[/color] == usart_flag_get([color=#bd63c5]EVAL_COM[/color], USART_FLAG_TBE)); [color=#0000ff]return[/color] [color=#808080]ch[/color]; } 以下是从机程序: [color=#808080]#include[/color][color=#0000ff] [/color][color=#a31515] [/color] [color=#808080]#include[/color][color=#0000ff] [/color][color=#a31515]"gd32f3x0.h"[/color] [color=#808080]#include[/color][color=#0000ff] [/color][color=#a31515]"gd32f350r_eval.h"[/color] [color=#808080]#define[/color][color=#0000ff] [/color][color=#bd63c5]I2C0_OWN_ADDRESS7[/color][color=#0000ff] [/color][color=#09885a]0x[/color]45 [color=#0000ff]uint8_t[/color] i2c_receiver[16]; [color=#0000ff]void[/color] rcu_config([color=#0000ff]void[/color]); [color=#0000ff]void[/color] gpio_config([color=#0000ff]void[/color]); [color=#0000ff]void[/color] i2c_config([color=#0000ff]void[/color]); [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] main function[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]int[/color] main([color=#0000ff]void[/color]) { [color=#0000ff]int[/color] i; gd_eval_com_init([color=#bd63c5]EVAL_COM[/color]); [color=#008000] /* RCU configure */[/color] rcu_config(); [color=#008000] /* GPIO configure */[/color] gpio_config(); [color=#008000] /* I2C configure */[/color] i2c_config(); i = 0; printf([color=#a31515]"start to wait\r\n"[/color]); [color=#008000] /* wait until ADDSEND bit is set */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)); [color=#008000] /* clear ADDSEND bit */[/color] printf([color=#a31515]"address match\r\n"[/color]); i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); printf([color=#a31515]"receive:\r\n"[/color]); [color=#0000ff]for[/color](i = 0; i < 16; i++) { [color=#008000] /* wait until the RBNE bit is set */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C0, I2C_FLAG_RBNE)); [color=#008000] /* read a data byte from I2C_DATA */[/color] i2c_receiver[i] = i2c_data_receive(I2C0); printf([color=#a31515]"%x "[/color], i2c_receiver[i]); } [color=#008000] /* wait until the STPDET bit is set */[/color] [color=#0000ff]while[/color](!i2c_flag_get(I2C0, I2C_FLAG_STPDET)); [color=#008000] /* clear the STPDET bit */[/color] i2c_enable(I2C0); printf([color=#a31515]"\n"[/color]); [color=#0000ff]while[/color](1) { } } [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] enable the peripheral clock[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]void[/color] rcu_config([color=#0000ff]void[/color]) { [color=#008000] /* enable GPIOB clock */[/color] rcu_periph_clock_enable(RCU_GPIOB); [color=#008000] /* enable I2C0 clock */[/color] rcu_periph_clock_enable(RCU_I2C0); } [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] configure the GPIO ports[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]void[/color] gpio_config([color=#0000ff]void[/color]) { [color=#008000] /* connect PB6 to I2C0_SCL */[/color] gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_6); [color=#008000] /* connect PB7 to I2C0_SDA */[/color] gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_7); [color=#008000] /* configure GPIO pins of I2C0 */[/color] gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_6); gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_6); gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_7); gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_7); } [color=#008000]/*![/color] [color=#008000] [/color][color=#0000ff]\brief[/color][color=#008000] configure the I2C0 interface[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]in[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\param[/color][color=#008000][[/color][color=#0000ff]out[/color][color=#008000]] [/color][color=#808080]none[/color] [color=#008000] [/color][color=#0000ff]\retval[/color][color=#008000] none[/color] [color=#008000]*/[/color] [color=#0000ff]void[/color] i2c_config([color=#0000ff]void[/color]) { [color=#008000] /* I2C clock configure */[/color] i2c_clock_config(I2C0, 100000, I2C_DTCY_2); [color=#008000] /* I2C address configure */[/color] i2c_mode_addr_config(I2C0, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, [color=#bd63c5]I2C0_OWN_ADDRESS7[/color]); [color=#008000] /* enable I2C0 */[/color] i2c_enable(I2C0); [color=#008000] /* enable acknowledge */[/color] i2c_ack_config(I2C0, I2C_ACK_ENABLE); } [color=#008000]/* retarget the C library printf function to the USART */[/color] [color=#0000ff]int[/color] fputc([color=#0000ff]int[/color] [color=#808080]ch[/color], FILE *[color=#808080]f[/color]) { usart_data_transmit([color=#bd63c5]EVAL_COM[/color], ([color=#0000ff]uint8_t[/color]) ch); [color=#0000ff]while[/color]([color=#2f4f4f]RESET[/color] == usart_flag_get([color=#bd63c5]EVAL_COM[/color], USART_FLAG_TBE)); [color=#0000ff]return[/color] [color=#808080]ch[/color]; } [/font][/backcolor] [font=Consolas, Courier New, monospace][backcolor=rgb(255, 255, 255)]按照我的理解,主机不论是否有从机存在,应该必定会有从机地址发出来的信号,有ACK回应那么说明从机识别成功。[/backcolor][/font] [font=Consolas, Courier New, monospace][backcolor=rgb(255, 255, 255)]我的iic1的SCL和SDA都外加了上拉电阻到3.3V。[/backcolor][/font] [font=Consolas, Courier New, monospace][backcolor=rgb(255, 255, 255)]iic1是否有什么需要特殊处理的地方?是否是管脚不对?我从例程里查看它使用iic1的时候也是使用的PB10和PB11[/backcolor][/font] 2034浏览量 0回复量 关注量 -
请问如何识别GD32F150系列芯片? sos
请问可以用FMC_PID寄存器,可靠地识别GD32F150系列地芯片吗? 如果可以,请问有谁知道PID编码的规则吗? 谢谢
2151浏览量 0回复量 关注量