IIC /I2C CH32V203C8T6 作為從模式,主設(shè)備是ARM Linux主機(jī) 利用IIC detect 不到地址

主設(shè)備是IIc 總線正常 總線掛載的設(shè)備也正常,用I2Ctools detect無法找到地址。

  1. 正常情況下,主設(shè)備是可以detect到總線上的地址的

d8db335c791dc61825f182195571501.png

2.利用iic 示例程序 將i2c1 改為2,然后對應(yīng)修改,修改為從模式,主機(jī)使用detect 命令無法detect到

image.png

3.硬件原理圖如圖所示:

313acd1786db59aa412c59b5cf3d9b8.png

4.代碼見附件


/**********************************?(C)?COPYRIGHT?*******************************
?*?File?Name??????????:?main.c
?*?Author?????????????:?WCH
?*?Version????????????:?V1.0.0
?*?Date???????????????:?2021/06/06
?*?Description????????:?Main?program?body.
*********************************************************************************
*?Copyright?(c)?2021?Nanjing?Qinheng?Microelectronics?Co.,?Ltd.
*?Attention:?This?software?(modified?or?not)?and?binary?are?used?for?
*?microcontroller?manufactured?by?Nanjing?Qinheng?Microelectronics.
*******************************************************************************/

/*
?*@Note
?7-bit?addressing?mode,?master/slave?mode,?transceiver?routine:
?I2C1_SCL(PB8)\I2C1_SDA(PB9).
?This?routine?demonstrates?that?Master?sends?and?Slave?receives.
Note:?The?two?boards?download?the?Master?and?Slave?programs?respectively,
and?power?on?at?the?same?time.
?????Hardware?connection:PB8?--?PB8
?????????????????????????PB9?--?PB9

*/

#include?"debug.h"

/*?I2C?Mode?Definition?*/
#define?HOST_MODE???0
#define?SLAVE_MODE???1
#define?CLOSE_IIC?????2
/*?I2C?Communication?Mode?Selection?*/
//#define?I2C_MODE???HOST_MODE
#define?I2C_MODE???SLAVE_MODE
//#define?I2C_MODE???CLOSE_IIC
/*?Global?define?*/
#define?Size???6
#define?RXAdderss???0x22
#define?TxAdderss???0x22

/*?Global?Variable?*/
u8?TxData[Size]?=?{?0x01,?0x02,?0x03,?0x04,?0x05,?0x06?};
u8?RxData[5][Size];

/*********************************************************************
?*?@fn??????IIC_Init
?*
?*?@brief???Initializes?the?IIC?peripheral.
?*
?*?@return??none
?*/
void?IIC_Init(u32?bound,?u16?address)
{
	GPIO_InitTypeDef?GPIO_InitStructure={0};
	I2C_InitTypeDef?I2C_InitTSturcture={0};

	RCC_APB2PeriphClockCmd(?RCC_APB2Periph_GPIOB,?ENABLE?);
	//GPIO_PinRemapConfig(GPIO_Remap_I2C1,?ENABLE);
	RCC_APB1PeriphClockCmd(?RCC_APB1Periph_I2C2,?ENABLE?);

	GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_OD;
	GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
	GPIO_Init(?GPIOB,?&GPIO_InitStructure?);

	GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_11;
	GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_OD;
	GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
	GPIO_Init(?GPIOB,?&GPIO_InitStructure?);

	I2C_InitTSturcture.I2C_ClockSpeed?=?bound;
	I2C_InitTSturcture.I2C_Mode?=?I2C_Mode_I2C;
	I2C_InitTSturcture.I2C_DutyCycle?=?I2C_DutyCycle_16_9;
	I2C_InitTSturcture.I2C_OwnAddress1?=?address;
	I2C_InitTSturcture.I2C_Ack?=?I2C_Ack_Enable;
	I2C_InitTSturcture.I2C_AcknowledgedAddress?=?I2C_AcknowledgedAddress_7bit;
????I2C_Init(?I2C2,?&I2C_InitTSturcture?);

	I2C_Cmd(?I2C2,?ENABLE?);


	//I2C_AcknowledgeConfig(?I2C2,?ENABLE?);


}

/*********************************************************************
?*?@fn??????main
?*
?*?@brief???Main?program.
?*
?*?@return??none
?*/
int?main(void)
{
????u8?i?=?0;
	u8?j?=?0;
	u8?p?=?0;
????Delay_Init();
????USART_Printf_Init(?115200?);
????printf(?"SystemClk:%d\r\n",?SystemCoreClock?);

#if?(I2C_MODE?==?HOST_MODE)
????printf("IIC?Host?mode\r\n");
	IIC_Init(?80000,?TxAdderss);

	for(?j?=0;?j?<?5;?j++)
	?{
????while(?I2C_GetFlagStatus(?I2C2,?I2C_FLAG_BUSY?)?!=?RESET?);

	I2C_GenerateSTART(?I2C2,?ENABLE?);

	while(?!I2C_CheckEvent(?I2C2,?I2C_EVENT_MASTER_MODE_SELECT?)?);
	I2C_Send7bitAddress(?I2C2,?0x02,?I2C_Direction_Transmitter?);

????while(?!I2C_CheckEvent(?I2C2,?I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED?)?);
?
????for(?i=0;?i<?6;i++?)
????{
????????if(?I2C_GetFlagStatus(?I2C2,?I2C_FLAG_TXE?)?!=??RESET?)
????????{
		????Delay_Ms(100);
????????????I2C_SendData(?I2C2,?TxData[i]?);
????????}
????}

????while(?!I2C_CheckEvent(?I2C2,?I2C_EVENT_MASTER_BYTE_TRANSMITTED?)?);
????I2C_GenerateSTOP(?I2C2,?ENABLE?);
	Delay_Ms(1000);
	?}

#elif?(I2C_MODE?==?SLAVE_MODE)
	printf("IIC?Slave?mode\r\n");
	IIC_Init(?80000,?RXAdderss);

	for(?p?=0;?p?<?5;?p++)
	{
	
????i?=?0;
	while(?!I2C_CheckEvent(?I2C2,?I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED?)?);
	printf("IIC?I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED?mode\r\n");
????while(?i?<?6?)
????{
????????if(?I2C_GetFlagStatus(?I2C2,?I2C_FLAG_RXNE?)?!=??RESET?)
????????{
????????????RxData[p][i]?=?I2C_ReceiveData(?I2C2?);
????????????i++;
????????}
????}
????????I2C2->CTLR1?&=?I2C2->CTLR1;
????}
	????printf(?"RxData:\r\n"?);
	?for(p=0;?p<5;?p++)
???{
????????for(?i?=?0;?i?<?6;?i++?)
		{
???????????printf(?"%02x?",?RxData[p][i]?);
		}
		???printf(?"\r\n?");
	?}
	?
?
#endif

	while(1)
	{

	????Delay_Ms(5000);
	????printf("iic?fuck?~~\r\n");
	}
}






變成smbus 模式可以識別了 但是多出來一個(gè)0c 地址


您好,IIC的SMBus模式支持設(shè)備和主機(jī)模式,程序中應(yīng)該配置為設(shè)備模式,關(guān)于IIC的地址模式,檢查一下程序中是不是配置使用了雙地址模式。此外可以檢查一下多出來地址是否由其他設(shè)備引起的,可以斷開連接排除一下。此外你可以直接在我們例程基礎(chǔ)上將其修改為IIC2,看看主從設(shè)備之間的通信是否正常,后續(xù)若有問題,可通過郵箱(lzs@wch.cn)和我溝通,若方便可將你的工程發(fā)至我的郵箱看一下。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频