TI中文支持网
TI专业的中文技术问题搜集分享网站

LDC1000 的 proximity data 读不出来

我用的MCU是NXP JN5168

以下是我参照网上能找到的代码和JN5168的data sheet写出来的代码

vAHI_SpiConfigure(1,                                               // 1 slave device
                                E_AHI_SPIM_MSB_FIRST,
                                0,0,                                           // Clock polarity unchanged, Phase: latch data on leading edge of the clock
                                8,                                              // Clock divider: Peripheral clock is divided by 2 x u8ClockDivider
                                FALSE,                                    // Interrupt disabled
                                FALSE);                                   // AutoSlaveSelect disabled
                                uint8 out;
vAHI_DioSetDirection(0, E_AHI_DIO0_INT);          // DIO0 is connected with CSB, set DIO0 as output

Below is my programming code

vAHI_SpiSelect(1); //Power mode off
vAHI_SpiStartTransfer16(0x0B00);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Rp max
vAHI_SpiStartTransfer16(0x0112);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Rp min
vAHI_SpiStartTransfer16(0x023C);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); // interrupt mode: comparator
vAHI_SpiStartTransfer16(0x0A02);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //High LSB
vAHI_SpiStartTransfer16(0x0684);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //High MSB
vAHI_SpiStartTransfer16(0x071C);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Low LSB
vAHI_SpiStartTransfer16(0x0820);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Low MSB
vAHI_SpiStartTransfer16(0x091C);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Power mode active
vAHI_SpiStartTransfer16(0x0B01);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy(); // End of initialisation

然而当我想读以下这些值的时候,出来的结果都是0x81, 0x82,0x86等等,proximity data 出来的结果也是0xa1和0xa2.

vAHI_SpiSelect(1); //Rp max
vAHI_SpiStartTransfer8(0x81);
out =u8AHI_SpiReadTransfer8();
DBG_vPrintf(TRACE_EXCEPTION, "0x%08x\r\n", out);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Rp min
vAHI_SpiStartTransfer8(0x82);
out =u8AHI_SpiReadTransfer8();
DBG_vPrintf(TRACE_EXCEPTION, "0x%08x\r\n", out);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //High LSB
vAHI_SpiStartTransfer8(0x86);
out =u8AHI_SpiReadTransfer8();
DBG_vPrintf(TRACE_EXCEPTION, "0x%08x\r\n", out);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //High MSB
vAHI_SpiStartTransfer8(0x87);
out =u8AHI_SpiReadTransfer8();
DBG_vPrintf(TRACE_EXCEPTION, "0x%08x\r\n", out);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Low LSB
vAHI_SpiStartTransfer8(0x88);
out =u8AHI_SpiReadTransfer8();
DBG_vPrintf(TRACE_EXCEPTION, "0x%08x\r\n", out);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

vAHI_SpiSelect(1); //Low MSB
vAHI_SpiStartTransfer8(0x89);
out =u8AHI_SpiReadTransfer8();
DBG_vPrintf(TRACE_EXCEPTION, "0x%08x\r\n", out);
vAHI_SpiSelect(0);
vAHI_SpiWaitBusy();

我想问一下我什么地方的代码写错了?谢谢大家,望各位指教。

user151383853:

看上去程序还是比较整齐的, 但没有条件实际调试一下找其中的原因, 我想说两个方面.

1. 先验证时序吧, 根据手册的时序规范, 看看数据传输中有没有完全符合时序要求.

2. DBG_vPrintf(), 我担心这个函数费的时间太久, 设备端是否会引入总线超时故障而关闭数据连接

赞(0)
未经允许不得转载:TI中文支持网 » LDC1000 的 proximity data 读不出来
分享到: 更多 (0)