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.
Fork of L3GD20_SPI by
Revision 3:6e935e7cec72, committed 2014-05-13
- Comitter:
- lelect
- Date:
- Tue May 13 09:56:43 2014 +0000
- Parent:
- 2:be6daa938101
- Commit message:
- .....I had mistaken the mosi and miso.
Changed in this revision
L3GD20.cpp | Show annotated file Show diff for this revision Revisions of this file |
L3GD20.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r be6daa938101 -r 6e935e7cec72 L3GD20.cpp --- a/L3GD20.cpp Mon May 12 11:47:43 2014 +0000 +++ b/L3GD20.cpp Tue May 13 09:56:43 2014 +0000 @@ -1,8 +1,8 @@ #include "mbed.h" #include "L3GD20.h" -L3GD20::L3GD20(PinName miso, PinName mosi, PinName scl, PinName cs,PinName interrupt2) - :_spi(miso,mosi,scl) +L3GD20::L3GD20(PinName mosi, PinName miso, PinName scl, PinName cs,PinName interrupt2) + :_spi(mosi,miso,scl) ,_cs(cs) ,_int2(interrupt2) { @@ -37,33 +37,28 @@ _config.CTRL_REG1.B.Enable=enable; _config.CTRL_REG1.b.PD=1; write(CtrlReg1,_config.CTRL_REG1.word); + allReadOut(); } void L3GD20::resetFIFO() { - enableFIFO(BYPASSmode,none,20); - enableFIFO(STREAMmode,watermark,20); + enableFIFO(L3GD20::BYPASSmode,L3GD20::none,20); + enableFIFO(L3GD20::STREAMmode,L3GD20::none); } void L3GD20::start(DIRECTION enable,void (*func)(anglerrates*)) { + reboot(); userFunction=func; _int2.rise(this,(&L3GD20::interrupt)); + start(enable); resetFIFO(); - start(enable); + enableFIFO(L3GD20::BYPASSmode,L3GD20::none,20); + enableFIFO(L3GD20::STREAMmode,L3GD20::none); } void L3GD20::interrupt(void) { - updateFIFO(); - if(FIFO.status==L3GD20::watermark) { - while(_status.FIFO_SRC_REG.B.FSS!=0) { - read(&value,XYZ); - if(NULL!=userFunction) { - userFunction(&value); - } - updateFIFO(); - if(FIFO.level==31) { - resetFIFO(); - } - } + read(&value,XYZ); + if(NULL!=userFunction) { + userFunction(&value); } } void L3GD20::stop() @@ -123,21 +118,22 @@ void L3GD20::enableFIFO(FIFO_mode mode,FIFOstatus interrupt,const int threshold) { _config.CTRL_REG5.b.FIFO_EN=1; - _config.CTRL_REG3.word=0; - if(interrupt&empty) { + if(interrupt==empty) { _config.CTRL_REG3.b.I2_Empty=1; - } else if(interrupt&watermark) { + } else if(interrupt==watermark) { _config.CTRL_REG3.b.I2_WTM=1; - } else if(interrupt&overrun) { + } else if(interrupt==overrun) { _config.CTRL_REG3.b.I2_ORun=1; + } else if(interrupt==none) { + _config.CTRL_REG3.b.I2_DRDY=1; } _config.FIFO_CTRL_REG.B.FM=mode; - if(threshold<=0) { - _config.FIFO_CTRL_REG.B.WTM=0; - } else if(threshold<30) { - _config.FIFO_CTRL_REG.B.WTM=31; - } else { - _config.FIFO_CTRL_REG.B.WTM=threshold; + if(threshold>0) { + if(threshold<30) { + _config.FIFO_CTRL_REG.B.WTM=31; + } else { + _config.FIFO_CTRL_REG.B.WTM=threshold; + } } write(CtrlReg3,_config.CTRL_REG3.word); write(CtrlReg5,_config.CTRL_REG5.word); @@ -159,6 +155,11 @@ FIFO.level=_status.FIFO_SRC_REG.B.FSS; return FIFO.level; } +void L3GD20::allReadOut() +{ + configReadOut(); + statusReadOut(); +} void L3GD20::configReadOut(void) { read(CtrlReg1,&_config.CTRL_REG1.word);
diff -r be6daa938101 -r 6e935e7cec72 L3GD20.h --- a/L3GD20.h Mon May 12 11:47:43 2014 +0000 +++ b/L3GD20.h Tue May 13 09:56:43 2014 +0000 @@ -28,7 +28,7 @@ class L3GD20 { public: - L3GD20(PinName miso, PinName mosi, PinName scl, PinName cs,PinName interrupt2=NC); + L3GD20(PinName mosi, PinName miso, PinName scl, PinName cs,PinName interrupt2=NC); typedef enum { null=0x00,WhoAmI=0x0F,CtrlReg1=0x20,CtrlReg2=0x21,CtrlReg3=0x22,CtrlReg4=0x23,CtrlReg5=0x24,Reference=0x25,OutTemp=0x26,StatusReg=0x27,OutXL=0x28,OutXH=0x29,OutYL=0x2A,OutYH=0x2B,OutZL=0x2C,OutZH=0x2D,FIFOCtrlReg=0x2E,FIFOSrcReg=0x2F,INT1Cfg=0x30,INT1Src=0x31,INT1ThsXH=0x32,INT1ThsXL=0x33,INT1ThsYH=0x34,INT1ThsYL=0x35,INT1ThsZH=0x36,INT1ThsZL=0x37,INT1Duration=0x38,READ=0x80 } RESISTER; @@ -53,7 +53,7 @@ typedef enum { BYPASSmode=0x0,FIFOmode,STREAMmode,STREAMtoFIFOmode,BYPASStoSTREAMmode } FIFO_mode; - /** @enum FIFOstatus + /** * FIFO status for cause of interruption\n * Example...L3GD20::watermark\n * See Datasheet 7.4_CTRL_REG3(p.33/44) @@ -61,9 +61,12 @@ typedef enum { none=0,empty,watermark,overrun } FIFOstatus; - struct tagFIFO { - FIFOstatus status; - int level; + /** + * @brief FIFO status info + */ + struct { + FIFOstatus status;///< Type of status is enum "FIFOstatus". cause of interruption(none,empty,watermark,overrun) + int level; ///< FIFO buffer level } FIFO; struct config { //read and write resister @@ -123,17 +126,18 @@ */ int readTemperature(); /** @fn void L3GD20::enableFIFO(FIFO_mode mode,FIFOstatus interrupt,const int threshold) - * @bref L3GD20mode need to reset(to bypass mode) when filled FIFObuffor + * @brief L3GD20mode need to reset(to bypass mode) when filled FIFObuffor * @param mode FIFOmode(L3GD20::BYPASSmode,FIFOmode,STREAMmode,STREAMtoFIFOmode,BYPASStoSTREAMmode) * @param interrupt cause of interrupt(L3GD20::none,empty,watermark,overrun) * @param threshold interruption threshold(1 to 30 vaild) */ - void enableFIFO(FIFO_mode mode,FIFOstatus interrupt,const int threshold=30); + void enableFIFO(FIFO_mode mode,FIFOstatus interrupt,const int threshold=0); /** @fn int L3GD20::updateFIFO(void) - * @bref Update FIFO status + * @brief Update FIFO status * @return FIFO buffer level */ int updateFIFO(void); + void allReadOut(); anglerrates value;///< @brief latest angler rates protected: //write command to resister