MoistureSoftware/Source/FM24.c

135 lines
3.3 KiB
C
Raw Normal View History

2025-09-28 09:17:22 +00:00
/**************** (C) COPYRIGHT 2023 ɽ<><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿƼ<DCBF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ *******************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: Kaiser
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> :
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>:
*********************************** <EFBFBD>޶<EFBFBD><EFBFBD><EFBFBD>¼ ************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>:
* <EFBFBD>޶<EFBFBD><EFBFBD><EFBFBD>:
********************************************************************************/
/******************************** <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> *************************************
*
*******************************************************************************/
#include "i2c.h"
#define FM24_ADDR 0xA0
#define ACK 1
#define NOACK 0
#include "i2c.h"
#define FM24_ADDR 0xA0
#define ACK 1
#define NOACK 0
void FM24_Write(uint16_t addr, uint8_t *data, uint8_t len)
{
I2C2_Start();
I2C2_SendByte(FM24_ADDR);
I2C2_Wait_ACK();
I2C2_SendByte(addr >> 8);
I2C2_Wait_ACK();
I2C2_SendByte(addr & 0xFF);
I2C2_Wait_ACK();
while (len--) {
I2C2_SendByte(*data++);
I2C2_Wait_ACK();
}
I2C2_Stop();
}
void FM24_Read(uint16_t addr, uint8_t *data, uint8_t len)
{
I2C2_Start();
I2C2_SendByte(FM24_ADDR);
I2C2_Wait_ACK();
I2C2_SendByte(addr >> 8);
I2C2_Wait_ACK();
I2C2_SendByte(addr & 0xFF);
I2C2_Wait_ACK();
I2C2_Start();
I2C2_SendByte(FM24_ADDR | 0x01);
I2C2_Wait_ACK();
while (len--) {
*data++ = I2C2_ReadByte(len ? ACK : NOACK);
}
I2C2_Stop();
}
void FM24Init()
{
I2C2_Init();
}
//void FM24_Write(uint16_t addr, uint8_t *data, uint8_t len)
//{
// I2C2_Start();
// I2C2_SendByte(FM24_ADDR);
// I2C2_Wait_ACK();
// I2C2_SendByte(addr & 0x00FF);
// I2C2_Wait_ACK();
// I2C2_SendByte(addr >> 8);
// I2C2_Wait_ACK();
//// I2C2_SendByte(addr & 0x00FF);
//// I2C2_Wait_ACK();
// while (len--) {
// I2C2_SendByte(*data++);
// I2C2_Wait_ACK();
// }
// I2C2_Stop();
//}
//void FM24_Read(uint16_t addr, uint8_t *data, uint8_t len)
//{
// uint8_t value;
// I2C2_Start();
// I2C2_SendByte(FM24_ADDR);
// I2C2_Wait_ACK();
// I2C2_SendByte(addr & 0x00FF);
// I2C2_Wait_ACK();
// I2C2_SendByte(addr >> 8);
// I2C2_Wait_ACK();
// I2C2_Wait_ACK();
// I2C2_SendByte(addr & 0x00FF);
// I2C2_Start();
// I2C2_SendByte(FM24_ADDR | 0x01);
// I2C2_Wait_ACK();
// while (len--) {
// *data++ = I2C2_ReadByte(len ? ACK : NOACK);
// }
// I2C2_Stop();
//}
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>׼д<D7BC><D0B4> <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪFM24CL16 <20><><EFBFBD>Ĵӻ<C4B4><D3BB><EFBFBD>ַ<EFBFBD>ֽ<EFBFBD>Ϊ 1 0 1 0 ҳ ѡ <20><> <20><>
//void FM24_Write(uint16_t addr, uint8_t *data, uint8_t len)
//{
// I2C2_Start();
// I2C2_SendByte(FM24_ADDR | ((addr &0xFF00)>>7) );
// I2C2_Wait_ACK();
// I2C2_SendByte(addr & 0x00FF);
// I2C2_Wait_ACK();
// while (len--) {
// I2C2_SendByte(*data++);
// I2C2_Wait_ACK();
// }
// I2C2_Stop();
//}
//void FM24_Read(uint16_t addr, uint8_t *data, uint8_t len)
//{
// I2C2_Start();
// I2C2_SendByte(FM24_ADDR | ((addr &0xFF00)>>7) );
// I2C2_Wait_ACK();
// I2C2_SendByte(addr & 0x00FF);
// I2C2_Wait_ACK();
// I2C2_Start();
// I2C2_SendByte(FM24_ADDR | ((addr &0xFF00)>>7)| 0x01);
// I2C2_Wait_ACK();
// while (len--) {
// *data++ = I2C2_ReadByte(len ? ACK : NOACK);
// }
// I2C2_Stop();
//}
//void FM24Init()
//{
// I2C2_Init();
//}
/******** (C) COPYRIGHT 2023 ɽ<><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿƼ<DCBF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ **** End Of File ********/