在线时间15 小时
UID2086045
注册时间2016-1-10
NXP金币0
该用户从未签到
注册会员

- 积分
- 117
- 最后登录
- 2022-6-26
|
本帖最后由 wjandsq 于 2020-7-17 12:56 编辑
/**
* Function Name : LPI2C0_read_bytes
* Parameters : uint8_t s_r_address, uint8_t s_reg_address, uint8_t *p_buffer, uint8_t n_bytes
* Modifies : uint8_t *p_buffer
* Returns : uint8_t
* Notes : Read from a slave
* Date : 2020/07/16 Check by Read 7 bytes from PCF8563
*/
uint8_t LPI2C0_read_bytes(uint8_t s_r_address, uint8_t s_reg_address, uint8_t *p_buffer, uint8_t n_bytes)
{
uint8_t n;
uint16_t time = 0;
uint16_t command;
if(bus_busy()) return (error |= (1 << BUSY));
generate_start_ACK(s_r_address - 1); /*<! Send I2C Address : Write 0xA2 */
transmit_data(s_reg_address); /*<! Send Register Address */
generate_stop(); /*<! Send stop */
for (n = 0; n < n_bytes; ++n) {
generate_start_ACK(s_r_address); /*<! Send Register Address : Write 0xA2 */
command = 0x0100; /*<! Read Command is bit15 to bit8 */
command |= 0; /*<! with (n_bytes - 1) parameter */
LPI2C0->MTDR = command; /*<! Send 1 byte Read Command with (n_bytes - 1) */
time = 0;
while (((LPI2C0->MFSR) >> 16 != 1) && (time < READING_TIMEOUT)) ++time;
if(time >= READING_TIMEOUT) {
LPI2C0->MCR |= (1 << 9); /*<! Reset Receive FIFO */
error |= (1 << NO_DATA_RECEIVED);
} else {
p_buffer[n] = (uint8_t)(LPI2C0->MRDR & 0x000000FF);
}
}
if(generate_stop()) return error;
else return OK;
}
该函数2020/07/16 通过验证,其余代码,可以在NXP 国外论坛搜索到。
|
|