Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:9ed1d493c235, committed 2016-03-04
- Comitter:
- TNU
- Date:
- Fri Mar 04 11:53:52 2016 +0000
- Parent:
- 1:e3ace426cee5
- Child:
- 4:534855b07d93
- Commit message:
- Use dataReady pin in gettrace; change shiftr
Changed in this revision
| LidarSpi.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LidarSpi.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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);
--- a/LidarSpi.h Thu Feb 25 08:14:59 2016 +0000
+++ b/LidarSpi.h Fri Mar 04 11:53:52 2016 +0000
@@ -154,7 +154,7 @@
};
- LidarSpi(PinName mosi, PinName miso, PinName clk, PinName chipSelect, PinName dr, PinName rs, PinName tr);
+ LidarSpi(PinName mosi, PinName miso, PinName clk, PinName chipSelect, PinName dr, PinName rs, PinName tr, PinName smpl);
int SpiSetting(long freq, int mode, Serial* pc);
int TxPacket(uint8_t* rData, uint16_t *rSz, uint8_t *tData, uint16_t tSz);
int TxPacketWord(uint8_t* rData, uint16_t *rSz, uint8_t *tData, uint16_t tSz);
@@ -190,6 +190,7 @@
DigitalOut chipS;
DigitalIn dataReady;
DigitalIn resetPin;
+ DigitalIn sampling;
DigitalOut trigger;