This is a class which contains function to interface with the MLX75320
Diff: LidarSpi.cpp
- Revision:
- 3:9ed1d493c235
- Parent:
- 1:e3ace426cee5
- Child:
- 5:87e211a23654
diff -r e3ace426cee5 -r 9ed1d493c235 LidarSpi.cpp --- a/LidarSpi.cpp Thu Feb 25 08:14:59 2016 +0000 +++ b/LidarSpi.cpp Fri Mar 04 11:53:52 2016 +0000 @@ -6,7 +6,7 @@ #include "LidarSpi.h" #include "MLX_BaseSPI.h" #define SPIFREQ 8000 -LidarSpi::LidarSpi(PinName mosi, PinName miso, PinName clk, PinName chipSelect, PinName dr, PinName rs, PinName tr):device(mosi, miso, clk), chipS(chipSelect), dataReady(dr),resetPin(rs), trigger(tr) +LidarSpi::LidarSpi(PinName mosi, PinName miso, PinName clk, PinName chipSelect, PinName dr, PinName rs, PinName tr, PinName smpl):device(mosi, miso, clk), chipS(chipSelect), dataReady(dr),resetPin(rs), trigger(tr), sampling(smpl) { //resetPin.write(1); chipS.write(1); @@ -657,6 +657,7 @@ int LidarSpi::GetTrace ( uint16_t *buf, uint16_t maxN, uint16_t nSam, uint16_t idx, Serial* pc){ + trigger.write(0); int res, a, b, i; uint32_t cnt; uint16_t rSz; @@ -697,9 +698,10 @@ cnt++; val >>= 1; } + nPack *= cnt; nPack /= 16; - + res = ReadReg(332, &val); // PORT_OVR_ACCUM_ACQ_OVR // pc->printf("PORT_OVR = %d\n", (val >> 16)); val = (val >> 16) & 3; // Get bits 0 and 1 @@ -724,26 +726,39 @@ pc->printf("GetTrace: bad value\n"); } - + // Write 1 to PORT_ACQU register and then wait res = ReadReg(0x146, &val); // PORT_ACQU if (res < 0){ pc->printf("ReadReg Error2\n\r"); goto END;} val = (val>>16) | 1; + trigger.write(1); res = WriteReg(0x146, val); // PORT_ACQU if (res < 0){ pc->printf("WriteReg Error3\n\r"); goto END;} // Wait till PORT_READY bit is set. + + res = ReadReg(470, &val); // PORT_READY cnt = 0; + /* while (((val & 0x10000) >> 16 != 1) && (cnt < 500)) { wait_us(50); res = ReadReg(470, &val); // PORT_READY cnt++; + }*/ + + while((!dataReady.read())&& (cnt<500)){ + wait_us(50); + cnt++; } + + + trigger.write(0); + pc-printf("Count: %d\n\r", cnt); // Encode the request and send it res = MLX_ReqReadTrc(tx); @@ -769,7 +784,7 @@ // Temporary pointer to uint16 data, for simplicity purpose u16ptr = (uint16_t*)rxL.data; //device.format(16,1); - trigger.write(1); + //trigger.write(1); for (a = 0; a < nPack; ++a) { res = MLX_EncodeStatusL1(&txL, 0, 0);