本帖最后由 zhcj66 于 2018-9-30 08:49 编辑
如题"AT24Cxx 芯片sot-23没有Ax地址管脚,这个地址应该是多少? "
这个芯片和常规的so-8封装的有什么区别 ,除了地址
在这里统一回复一下,芯片读写成功地址是0;问题还是出在程序上,用成了24CL64的程序了,这个芯片是24C02
下面是我的代码
- //AT24C02读写程序,测试成功。mcu采用的STM32 72MHz
- #define IIC_SDA_RCC RCC_APB2Periph_GPIOC
- #define IIC_SDA_PIN GPIO_Pin_4
- #define IIC_SDA_GPIOx GPIOC
- #define IIC_SCL_RCC RCC_APB2Periph_GPIOC
- #define IIC_SCL_PIN GPIO_Pin_5
- #define IIC_SCL_GPIOx GPIOC
- #define IIC_SDA_SET GPIO_SetBits(IIC_SDA_GPIOx,IIC_SDA_PIN)
- #define IIC_SDA_CLR GPIO_ResetBits(IIC_SDA_GPIOx,IIC_SDA_PIN)
- #define IIC_SDA_Get GPIO_ReadInputDataBit(IIC_SDA_GPIOx, IIC_SDA_PIN)
- #define IIC_SCL_SET GPIO_SetBits(IIC_SCL_GPIOx,IIC_SCL_PIN)
- #define IIC_SCL_CLR GPIO_ResetBits(IIC_SCL_GPIOx,IIC_SCL_PIN)
- #define IIC_SCL_Get GPIO_ReadInputDataBit(IIC_SCL_GPIOx, IIC_SCL_PIN)
- #define IIC_ReadAddr 0xA1 //器件地址以及读取操作
- #define IIC_WriteAddr 0xA0 //器件地址以及写入操作
- #define IIC_MaxAddr 0xFF //AT24C02最大地址
- void IIC_Delays(unsigned char ms)
- {
- static unsigned char i;
- while(ms--)
- {
- for(i = 0; i < 50; i++);
- }
- }
- void NOP(void)
- {
- ;
- }
- //把SDA管脚设置为输入
- void IIC_SDA_IN(void)
- {
-
- }
- //把SDA管脚设置为输出
- void IIC_SDA_OUT(void)
- {
-
- }
- void IIC_Start(void)
- {
- IIC_SDA_OUT();
- IIC_SDA_SET;
- IIC_SCL_SET;
- NOP();
- NOP();
- IIC_SDA_CLR;
- NOP();
- NOP();
- NOP();
- NOP();
- IIC_SCL_CLR;
- }
- void IIC_Stop(void)
- {
- IIC_SDA_OUT();
- IIC_SDA_CLR;
- NOP();
- NOP();
- IIC_SCL_SET;
- NOP();
- NOP();
- NOP();
- NOP();
- IIC_SDA_SET;
- }
- void IIC_Send(unsigned char Byte)
- {
- static unsigned char i;
- IIC_SDA_OUT();
- for (i = 0; i < 8; i++)
- {
- if((Byte & 0x80) == 0x80)
- {
- IIC_SDA_SET;
- }
- else
- {
- IIC_SDA_CLR;
- }
- NOP();
- IIC_SCL_SET;
- NOP();
- NOP();
- IIC_SCL_CLR;
- Byte = Byte << 1;
- }
- IIC_SDA_SET;
- NOP();
- NOP();
- IIC_SCL_SET;
- NOP();
- NOP();
- NOP();
- NOP();
- IIC_SCL_CLR;
- }
- unsigned char IIC_Read(void)
- {
- unsigned char i,read_data=0;
- IIC_SDA_IN();
- for (i = 0; i < 8; i++)
- {
- IIC_SCL_SET;
- read_data <<= 1;
- if(IIC_SDA_Get)
- {
- read_data = read_data | 0x01;
- }
- IIC_SCL_CLR;
- }
- return read_data;
- }
- void IIC_WriteByte(unsigned char Addr,unsigned char Data)
- {
- IIC_Start();
- IIC_Send(IIC_WriteAddr);
- IIC_Send(Addr);
- IIC_Send(Data);
- IIC_Stop();
- IIC_Delays(90);//如果填写偶数失败时,可以增加延时时间
- }
- void IIC_FillByte(unsigned char Data)//填充数据Data到整个EEPROM内
- {
- static unsigned char i;
- for(i = 0; i < IIC_MaxAddr; i++)
- {
- IIC_WriteByte(i, Data);
- }
- }
- unsigned char IIC_ReadByte(unsigned int ReadAddr)
- {
- static unsigned char read_data;
-
- IIC_Start();
- IIC_Send(IIC_WriteAddr);
- IIC_Send(ReadAddr);
- IIC_Start();
- IIC_Send(IIC_ReadAddr);
- read_data = IIC_Read();
- IIC_Stop();
- IIC_Delays(45);
- return read_data;
- }
- void IIC_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(IIC_SDA_RCC|IIC_SCL_RCC,ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = IIC_SDA_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(IIC_SDA_GPIOx,&GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = IIC_SCL_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(IIC_SCL_GPIOx,&GPIO_InitStructure);
- }
复制代码
同一个品牌 atmel的
一周热门 更多>