我们在读取Measurement Specialties MS5637的D1(0x40~0x4A)和D2(0x50~0x5A)寄存器时遇到了一些麻烦。 每次对这些寄存器进行I2C调用时,它们总是返回0.这很奇怪,因为我们可以正常读取PROM。
我们的设置如下: 我们有一个定制PCB,内置BLE121LR(带有嵌入式TI微控制器),连接到MS5637和其他一些传感器。
到目前为止,我们的程序是: 1.将复位写入0x1E 2.在0xA0~0xA5读取PROM 3.阅读D1& D2在0x40& 0x50 - >在任何OSR中,它总是返回0。
我希望有人能够发现我们的错误并帮助我们启动并运行MS5637。
我附上了我们正在运行的代码(BGscript),希望它能提供一些帮助。 在每个命令之前我都评论了它的功能:
#=======================================================================================
# MS5637 BaroWITHer
# address: 1110110x (write : x=0, read : x=1) EC ED
# RESET: 0x1E
# PROM READ: 0xA0 to 0xAE
# READ ADC: 0x00
#=======================================================================================
## RESET COMMAND
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\x1E")(MSResetwritten)
## WRITE TO PROM A0
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\xA0")(MSPromwritten)
## READ TO PROM A0
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 2)(i2c_result, data_len, prom(0:2))
## WRITE TO PROM A1
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\xA1")(MSPromwritten)
## READ TO PROM A1
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 2)(i2c_result, data_len, prom(2:2))
## WRITE TO PROM A2
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\xA2")(MSPromwritten)
## READ TO PROM A2
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 2)(i2c_result, data_len, prom(4:2))
## WRITE TO PROM A3
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\xA3")(MSPromwritten)
## READ TO PROM A3
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 2)(i2c_result, data_len, prom(6:2))
## WRITE TO PROM A4
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\xA4")(MSPromwritten)
## READ TO PROM A4
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 2)(i2c_result, data_len, prom(8:2))
## WRITE TO PROM A5
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\xA5")(MSPromwritten)
## READ TO PROM A5
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 2)(i2c_result, data_len, prom(10:2))
## WRITE THE PROM VALUES TO BLE SERVICE prom_handle
# call attributes_write(handle, offset, value_len, value_data)(result)
call attributes_write(prom_handle, 0, 12, prom(0:12))
#-----------------------------
# D1 & D2
#-----------------------------
## READ D1 WITH OSR=256
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\x40")(MSD1D2written)
## READ D1
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 3)(i2c_result, data_len, dvalues(0:3))
## READ D2 WITH OSR=256
#call hardware_i2c_write(address, stop, data_len, data_data)(written)
call hardware_i2c_write($EC, 1, 1, "\x50")(MSD1D2written)
## READ D2
#call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
call hardware_i2c_read($ED, 1, 3)(i2c_result, data_len, dvalues(3:3))
## WRITE THE D1 & D2 VALUES TO BLE SERVICE d2_handle
# call attributes_write(handle, offset, value_len, value_data)(result)
call attributes_write(d_handle, 0, 6, dvalues(0:6))
答案 0 :(得分:2)
经过多次实验,我回答了自己的问题,希望它可以帮助别人。
以下是阅读D1和EX的步骤。 MS5637上的D2值超过I2C:
答案 1 :(得分:1)
因此在使用BGScript的读/写命令时需要小心(仅供参考:我有一个关于如何在此处执行此操作的旧示例:http://www.sureshjoshi.com/embedded/ble112-how-to-use-i2c/)
如何阅读:
如果您想从寄存器中读取,则需要拨打电话 hardware_i2c_write使用7位设备地址,左移一次 然后在没有的情况下将您感兴趣的寄存器地址写入设备 设置停止标志(0)。
从器件将数据放在I2C线上,以便接收 它,用相同的设备地址调用hardware_i2c_read,设置 将标志停止为1(让设备知道你完成了它)和 读取1个字节的数据(包含寄存器位信息)。
写下:
第一个字节是您要写入的寄存器和 第二个是您要写入的数据。请确认 用“\ x”
转义数据的第二个字节
以上假设您有一个使用Address - >结构的设备。注册 - >价值......查看您的数据表(http://www.meas-spec.com/downloads/MS5637-02BA03.pdf),它似乎只是地址 - >值。奇怪。
要记住的一个关键事项是读/写命令的'地址'部分始终是相同的!在内部,LSB变为1或0,具体取决于命令本身。
const MS5637_I2C_ADDRESS = $88
## RESET COMMAND
call hardware_i2c_write(MS5637_I2C_ADDRESS, 1, 1, "\x1E")(MSResetwritten)
此外,对于您的D1 / D2难题,请尝试将初始写入的停止位设置为0,以便您的设备知道它仍在等待命令(老实说,即使I2C是一个规范,每个设备都有它自己的古怪实现):
## READ D1
call hardware_i2c_write(MS5637_I2C_ADDRESS, 0, 1, "\x40")(MSD1D2written)
call hardware_i2c_read(MS5637_I2C_ADDRESS, 1, 3)(i2c_result, data_len, dvalues(0:3))
答案 2 :(得分:0)
您需要做的另一件事是在写入0x40和0x00之间延迟一点。如果您没有延迟,并且0x40命令尚未完成,您将返回0或无效值。适当的延迟如下:
> switch (cmd & 0x0f) {
> case MS5637_CMD_ADC_256 : wait_us(900); break;
> case MS5637_CMD_ADC_512 : wait_ms(3); break;
> case MS5637_CMD_ADC_1024: wait_ms(4); break;
> case MS5637_CMD_ADC_2048: wait_ms(6); break;
> case MS5637_CMD_ADC_4096: wait_ms(10); break; }