MTK6580M 调试ADC mcp3421 I2C接口

本文档详细介绍了如何在MTK6580M平台上调试MCP3421 ADC芯片的I2C通信。提供了I2C写入和读取寄存器的函数实现,以及驱动注册和卸载的代码。通过这些函数,可以实现对MCP3421的控制并读取ADC转换结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调试MCP3421

I2C 通道2



#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/kthread.h>
#include <linux/input.h>

#include <linux/miscdevice.h>
#include <linux/i2c.h>
#include <asm/uaccess.h>

#include <linux/of_gpio.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/wait.h>


struct i2c_client *mcp3421_i2c_client;

#define ADC_LOG pr_debug
#define MCP3421_I2C_MAX_LOOP 3

#ifndef BOOL
typedef unsigned char   BOOL;
#endif



static BOOL mcp3421_i2c_write_reg_len(unsigned char data)
{
    BOOL ack=0;
    unsigned char ret;
    unsigned char wrbuf[2];

    wrbuf[0] = data;
    
    ret = i2c_master_send(mcp3421_i2c_client, wrbuf, 1);
    if (ret != 1)
    {
        ADC_LOG("leo_code  i2c_master_send failed  %s \r\n", __func__);

        //dev_err(&mcp3421_i2c_client->dev,"%s: i2c_master_recv() failed, ret=%d\n",__func__, ret);
    &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值