请选择 进入手机版 | 继续访问电脑版
查看: 1365|回复: 0

[S32] S32K144 LPI2C (Low Power Inter-Integrated Circuit) 多字节读取函数

[复制链接]

该用户从未签到

3

主题

15

帖子

1

注册会员

Rank: 2

积分
117
最后登录
2022-6-26
发表于 2020-7-17 09:45:05 | 显示全部楼层 |阅读模式
本帖最后由 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 国外论坛搜索到。




我知道答案 目前已有0人回答
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /4 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2024-4-17 01:57 , Processed in 0.112541 second(s), 20 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表