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 4:1f708415c442, committed 2014-05-13
- Comitter:
- piyamate
- Date:
- Tue May 13 13:54:32 2014 +0000
- Parent:
- 3:1d0c09e43e22
- Commit message:
- working !
Changed in this revision
--- a/OTP.cpp Tue May 13 11:04:01 2014 +0000 +++ b/OTP.cpp Tue May 13 13:54:32 2014 +0000 @@ -7,15 +7,7 @@ CSn( DigitalOut(CSn_pin, 0) ), pc( pc ) { - factory_section = 0; - I2C_A = 0; - CCW = 0; - Z = 0; - output_md1 = 0; - output_md0 = 0; - pwmDIS = 0; - MagCompEN = 0; - PWMhalfEN_IndexWidth = 0; + clear_registers(); } void OTP::setup() @@ -177,15 +169,15 @@ //factory_section { - PDIO = 0; - wait_us(30); + factory_section = 0; for(int i=0; i<29; i++) { PDIO = ( factory_section>>(29-i-1) )&1; + wait_us(15); CLK = 1; wait_us(30); CLK = 0; - wait_us(30); + wait_us(15); } } @@ -232,26 +224,35 @@ //mbit0 CLK = 1; - wait_us(15); //T_PROG_BURN + wait_us(T_PROG_BURN); CLK = 0; - wait_us(30); + wait_us(T_PROG_REFRESH); //factory_section for(int i=0; i<29; i++) { CLK = 1; - wait_us(15); //T_PROG_BURN + wait_us(T_PROG_BURN); CLK = 0; - wait_us(30); + wait_us(T_PROG_REFRESH); } //I2C_A for(int i=0; i<5; i++) { CLK = 1; - wait_us(15); //T_PROG_BURN + wait_us(T_PROG_BURN); CLK = 0; - wait_us(30); + wait_us(T_PROG_REFRESH); + } + + //burn other bits + for(int i=0; i<19; i++) + { + CLK = 1; + wait_us(T_PROG_BURN); + CLK = 0; + wait_us(T_PROG_REFRESH); } } else @@ -267,4 +268,17 @@ void OTP::set_id(uint8_t id) { I2C_A = ID_to_I2C_A(id); +} + +void OTP::clear_registers() +{ + factory_section = 0; + I2C_A = 0; + CCW = 0; + Z = 0; + output_md1 = 0; + output_md0 = 0; + pwmDIS = 0; + MagCompEN = 0; + PWMhalfEN_IndexWidth = 0; } \ No newline at end of file
--- a/OTP.h Tue May 13 11:04:01 2014 +0000 +++ b/OTP.h Tue May 13 13:54:32 2014 +0000 @@ -10,6 +10,7 @@ void write(); void prog(); void set_id(uint8_t id); + void clear_registers(); uint32_t factory_section; uint32_t I2C_A; //I2C address <5:1> @@ -21,6 +22,9 @@ uint32_t PWMhalfEN_IndexWidth; private: + static const int T_PROG_BURN = 15; + static const int T_PROG_REFRESH = 200; + DigitalInOut PDIO, CLK; DigitalOut CSn; Serial pc;
--- a/main.cpp Tue May 13 11:04:01 2014 +0000 +++ b/main.cpp Tue May 13 13:54:32 2014 +0000 @@ -55,12 +55,11 @@ pc.printf("Input new device ID in hex (0x80 to 0xFE): 0x"); pc.scanf("%x", &id); - id = 0x90; - id &= 0xFC; if(id>=0x80 && id<=0xFE) { valid = 1; + otp.clear_registers(); otp.set_id(id); } }while(valid==0);