最近项目上用到了sgm58031这款芯片,经过两天时间的调试,成功实现了对于该芯片的读取和相关配置。
sgm58031是圣邦微的一款4通道输入ADC芯片,芯片地址为1001000,读操作为1,写操作为0,即写操作为90h,读操作为91h,本项目需要对其1、2通道数据进行读取,阅读手册发现,需要先配置相关的寄存器进行通道切换。
Write to Config Register:First byte: 0b10010000 (first 7-bit I 2 C address followedby a low read/write bit)Second byte: 0b00000001 (points to Config register)Third byte: 0b10000100 (MSB of the Config register tobe written)Fourth byte: 0b10000011 (LSB of the Config register tobe written)Write to Pointer Register:First byte: 0b10010000 (first 7-bit I 2 C address followedby a low read/write bit)Second byte: 0b00000000 (points to Conversionregister)Read Conversion Register:First byte: 0b10010001 (first 7-bit I 2 C address followedby a high read/write bit)Second byte: the SGM58031 response with the MSB ofthe Conversion registerThird byte: the SGM58031 response with the LSB of the Conversion register
状态寄存器具体对应需参照该芯片数据手册,具体操作流程如下:
c5h对应第一个单端输入通道,d5h对应第二个单端输入通道,对两个通道进行读取时需要按上面流程进行切换,具体iic实现代码较为简单 。
输出计算为:x/32768 * 2.048