海思NB-IOT模块HI2115芯片I2C通信
1. 首先确定硬件上I2C的引脚,手册上并没有,海思技术支持说是14和15脚,我们用的是12和13脚,问题在于,如果是硬件I2C应该不能随便换个引脚吧,难道是模拟的时序?
2. 下一个奇怪的地方,这个寄存器居然只有两行,没其他地方使用,真奇怪?
看下相关的代码
3. PIO的设置
static I2C_RET i2c_set_pio(PIN pin, FUNC i2c_func)
{
if (pin != PIN_NONE)
{
if(!pio_set_function(pin, i2c_func))
{
return I2C_RET_ERROR;
}
}
}
继续往下看,最终设置的是下面的,还是直接写寄存器的意思?不过后面的半句话不太明白什么意思,意思是把这个数组放到外设的代码段里面。
/**
* Direct access to register address space for all PIOs
*/
static volatile HAL_PIO_REGISTER_MAP hal_pio_registers[ PIN_MAX_NUMBER ] __attribute__((section(".peripherals")));
果然是对应寄存器的值
typedef struct
{
//lint -esym(754,HAL_PIO_REGISTER_MAP::*) Some of these aren't used directly.
uint32 pio_claim; //!< Peripheral claim register - register layout is different for a read compared to a write
uint32 pio_ctrl; //!< PIO_CTRL register
uint32 pio_irq_clr; //!< PIO_IRQ_CLR register
uint32 reserved_0; //!< Reserved
uint32 reserved_1; //!< Reserved
uint32 pio_ctrl_bitset; //!< PIO_CTRL_BITSET register
uint32 reserved_2; //!< Reserved
uint32 reserved_3; //!< Reserved
uint32 reserved_4; //!< Reserved
uint32 pio_ctrl_bitclr; //!< PIO_CTRL_BITCLR register
uint32 reserved_5; //!< Reserved
uint32 reserved_6; //!< Reserved
uint32 reserved_7; //!< Reserved
uint32 pio_ctrl_bittog; //!< PIO_CTRL_BITTOG register
uint32 reserved_8; //!< Reserved
uint32 reserved_9; //!< Reserved
} HAL_PIO_REGISTER_MAP;
看下FUNC的配置,这个应该是引脚复用图吧,难道每个引脚都可以随便作为任何功能?
typedef enum
{
FUNC_UNCLAIMED = 0,
FUNC_GPIO = 1,
FUNC_UART0_TXD = 2,
FUNC_UART0_TXIR = 3,
FUNC_UART0_O2 = 4,
FUNC_UART0_O1 = 5,
FUNC_UART0_RTS = 6,
FUNC_UART0_DTR = 7,
FUNC_UART0_RXD = 8,
FUNC_UART0_RXIR = 9,
FUNC_UART0_CTS = 10,
FUNC_UART0_DCD = 11,
FUNC_UART0_DSR = 12,
FUNC_UART0_RI = 13,
FUNC_UART1_TXD = 14,
FUNC_UART1_TXIR = 15,
FUNC_UART1_O2 = 16,
FUNC_UART1_O1 = 17,
FUNC_UART1_RTS = 18,
FUNC_UART1_DTR = 19,
FUNC_UART1_RXD = 20,
FUNC_UART1_RXIR = 21,
FUNC_UART1_CTS = 22,
FUNC_UART1_DCD = 23,
FUNC_UART1_DSR = 24,
FUNC_UART1_RI = 25,
FUNC_LPUART_RXD = 26,
FUNC_LPUART_TXD = 27,
FUNC_DBG_CLK0 = 112,
FUNC_DBG_CLK1 = 113,
FUNC_DBG_CLK2 = 114,
FUNC_DBG_CLK3 = 115,
FUNC_RADIO_PIO = 128,
FUNC_UICC_CLK = 129,
FUNC_UICC_RST = 130,
FUNC_UICC_IO = 131,
FUNC_DSP_TMS = 132,
FUNC_DSP_TDI = 133,
FUNC_DSP_TDO = 134,
FUNC_DSP_TRST = 135,
FUNC_SPI_SCLK = 136,
FUNC_SPI_CSB = 137,
FUNC_SPI_UNIDIR_IN = 138,
FUNC_SPI_UNIDIR_OUT = 139,
FUNC_SPI_BIDIR_DATA0 = 140,
FUNC_SPI_BIDIR_DATA1 = 141,
FUNC_SPI_BIDIR_DATA2 = 142,
FUNC_SPI_BIDIR_DATA3 = 143,
FUNC_DSP_TCK = 144,
FUNC_RADIO_RFFE_SCLK = 145,
FUNC_RADIO_RFFE_SDATA = 146,
FUNC_PWM0 = 192,
FUNC_PWM0B = 193,
FUNC_PWM1 = 194,
FUNC_PWM1B = 195,
FUNC_SSP0TXD = 196,
FUNC_SSP0RXD = 197,
FUNC_SSP0TRX = 198,
FUNC_SSP0CLK = 199,
FUNC_SSP0FSS = 200,
FUNC_SSP1TXD = 201,
FUNC_SSP1RXD = 202,
FUNC_SSP1TRX = 203,
FUNC_SSP1CLK = 204,
FUNC_SSP1FSS = 205,
FUNC_I2C0_SDA = 206,
FUNC_I2C0_SCL = 207,
FUNC_I2C1_SDA = 208,
FUNC_I2C1_SCL = 209,
FUNC_UART2_TXD = 210,
FUNC_UART2_TXIR = 211,
FUNC_UART2_O2 = 212,
FUNC_UART2_O1 = 213,
FUNC_UART2_RTS = 214,
FUNC_UART2_DTR = 215,
FUNC_UART2_RXD = 216,
FUNC_UART2_RXIR = 217,
FUNC_UART2_CTS = 218,
FUNC_UART2_DCD = 219,
FUNC_UART2_DSR = 220,
FUNC_UART2_RI = 221,
FUNC_MAX = 222 //!< Limit to range of valid values
} FUNC;
芯片的数据手册,这样说起来,这24个PIO可以复用到任何的外设上。现在问题是一共有40个PIO,说的是那24个PIO?
4. 说是PIO分为4个区域,每个区域的电压似乎可以不一样