-
Thank you Gordon,
Sorry, I have no experience to flash a MCU before , to avoid unexpected situation and also can develop properly, would flash it through STM32Discovery board be the easiest and best way to do it?
I am using Espruino Pico which is chip STM32F401CDU6, should I choose the discovery board with the exact same chip? or would any discovery board comes with F3/F4 chip be fine? any recommendation on boards ?
A naive way I am thinking for the first option based what I read from the Advanced Debug is:
- Connect the discovery board to the PICO with ST-Link based on the table provided
- Modify the file based on the "Gachats"
- Install st-link tools from git
- Run the command line provided
But I am not very sure where those files "ESPRUINOBOARD.py or PICO_XX.py"are located, and how to use them. would this process be able to make the PICO code in STM32cubeIDE Embedded C environment?
I need to run the program in very fast speed, and inline C is also not fast enough, Arduino is very close to C, I think Arduino might be faster than inline C?, is it possible to flash PICO as Arduino? the costs might be cheaper for me if this is possible
Thank you
- Connect the discovery board to the PICO with ST-Link based on the table provided
-
-
I just tried 3 and it looks like the same output as 0.02 that I have before
is there a way to check the data without using print? and another way to call the function repeatedly if we want to call it fast? for visualizing the data, one other method I can think of is writes file, I believe the write file should be faster than console.log(), but I am concerning if write file write it to the flash memory? if so, i am afraid I do not have enough flash for the data in espruino .
Yes, I will try that inline c, I tried the one with adding "complied" in the code and it did not work, but does increase a bit speed.
OHHHHH no, if gettime return in second, that proof the 833 Hz is impossible with javascript
-
-
The FIFO mode provides the correct data but I have to reset every time to get another round of FIFO data, since it will stop filling after it full. The reset process clear everything that might stall in the FIFO and results in missing some data (because timestamp incremented a lot ), so it is not very ideal
So ideally, I would like to save the program in flash memory in Epsurino, and when I supply the power to Epsurino or turn on some switch, it will start to fetch data
So this is how I would use those data:
For now,
I will integrate the gyro over that timestamp that's outputting at 833Hz, then use UART to pass the integrated gyro data and accelerometer to the data handling unit.So I would prefer to integrate every set of data at every 833Hz = 0.0012s
I just realized you edit #24 I am gonna look at those links now
-
I will integrate the gyro over that time period, so I think I will every single set of data that output at 833Hz,
then I will use UART to pass the integrated data and accelerometer to the data handling unit."Is so, the FIFO buffer is probably filling up before each data item is removed from the buffer and the device is cramming in bytes until errors in output are seen. Could this be a possibility?"
I think this is possible. but if this is true, wouldn't it make it very hard to pull the data in high frequency?
Haha have a good time
-
-
I just tried setInterval(extraction,150);
but it is only outputting one correct data set this time.8539 -645 -18294 -256 126 4104 -668 4262111 0.02233409881 11 15 15 229 225 227 -669 3328 0.02214241027 11 11 19 229 227 223 -653 4864 0.02214145660
Oh sorry, on page 57/114 FIFO ODR can be 833Hz frequency range from 12.5 to 6.6kHz. so we choose 833Hz because it is a nice frequency for the algorithm that we are developing for processing the data
-
Hi Robin,
Thank you for helping me so much
Sorry if I misunderstand, I am not so sure how to measure the repeated part if you mean measure how fast the interval is running.
I put the measure time in the all read_FIFO, read_Normal, and read_Time and this is my output
Read FIFO 0.00033950805 946686551.91729545593 elapsed 0.00323581695 Read FIFO 0.00033664703 946686551.92159366607 elapsed 0.00324440002 Read FIFO 0.00037765502 946686551.92586135864 elapsed 0.00328826904 Read FIFO 0.00033760070 946686551.93021202087 elapsed 0.00324249267 Read FIFO 0.00037860870 946686551.93448162078 elapsed 0.00328826904 Read FIFO 0.00033855438 946686551.93883323669 elapsed 0.00324440002 Read Normal 0.00038623809 946686551.94312000274 elapsed 0.00335884094 Read Time 0.00034713745 946686551.94751930236 elapsed 0.00702095031 8793 -567 -18040 -23 -102 4237 undefined 3902886 0.03861045837 Read FIFO 0.00034427642 946686551.95695877075 elapsed 0.00325965881 Read FIFO 0.00038528442 946686551.96123790740 elapsed 0.00331974029 Read FIFO 0.00034427642 946686551.96561431884 elapsed 0.00326347351 Read FIFO 0.00038528442 946686551.96989727020 elapsed 0.00330162048 Read FIFO 0.00034523010 946686551.97425270080 elapsed 0.00325775146 Read FIFO 0.00034427642 946686551.97857093811 elapsed 0.00325298309 Read Normal 0.00034999847 946686551.98289966583 elapsed 0.00330257415 Read Time 0.00035190582 946686551.98722839355 elapsed 0.00691509246 8029 -1069 -14708 -24 -117 4237 undefined 3902939 0.03862571716
and the code looks like this
//Read timestamp function function readtime(ss) { var t = getTime(); var elapsed = 0; console.log( "Read Time " + (getTime()-t) + " " + t ); hi = SPI_read(FIFO_DATA_OUT_L,ss); hi2 = SPI_read(FIFO_DATA_OUT_H,ss); non = SPI_read(FIFO_DATA_OUT_L,ss); lo = SPI_read(FIFO_DATA_OUT_H,ss); step = SPI_read(FIFO_DATA_OUT_L,ss); step = SPI_read(FIFO_DATA_OUT_H,ss); hi2 = hi2 << 16; hi = hi << 8; Value = hi2 | hi | lo; elapsed = getTime()-t; console.log( "elapsed " + elapsed ); return Value; }
var st = 0; //var s2 = 0; //print( "OMX", "OMY", "OMZ","AX", "AY", "AZ",,"TEMP","TimeStamps"); //var start = getTime(); function extraction() { // "compiled"; //print(Ntotaldata()); st = getTime(); //if(((SPI_read(FIFO_STATUS2,ss))&0b00010000) != 0b00010000) //{ console.log( omx = read_FIFO(ss), omy = read_FIFO(ss), omz = read_FIFO(ss), ax = read_FIFO(ss), ay = read_FIFO(ss), az = read_FIFO(ss), temp = read_normal(ss), tm = readtime(ss), getTime()-st); // } } setInterval(extraction,0.002);
ss
function read_FIFO(ss) { var test; var t = getTime(); var elapsed = 0; console.log( "Read FIFO " + (getTime()-t) + " " + t ); test = signshort(SPI_read(FIFO_DATA_OUT_H,ss)<<8|SPI_read(FIFO_DATA_OUT_L,ss)); elapsed = getTime()-t; console.log( "elapsed " + elapsed ); return test } function read_normal(ss) { var test1; var t = getTime(); var elapsed = 0; console.log( "Read Normal " + (getTime()-t) + " " + t ); test = signshort(SPI_read(TEMP_OUT_H,ss)<<8 | SPI_read(TEMP_OUT_L,ss)); elapsed = getTime()-t; console.log( "elapsed " + elapsed ); return test1; }
I believe the time I measure is in millisecond, and I also measure the clock frequency of the SPI is running correctly at 10 MHz, so I think both system and SPI should techninilly running fast enough? and thank you again : )
yes, that is the IMU datasheet.
I configured FIFO as continuous mode so I can keep the data from the IMU with a set timestamp and it can keep running for hours.
The goal is to do the data collection at 833 Hz for hours and the output timestamps gap should be fixed (increment by 48 or 49 each timestamp). The FIFO mode provides the correct data but I have to reset every time to get the new set of data since it will stop filling after it full. The reset process result in missing some data, so it is not very ideal
Attached is the SPI clock frequency measured from the oscilloscope
-
Hi Robin and AkosLukacs,
Thank you for taking your time helping me.
Here is my code and output for measuring one read_FIFO, (compare with 1/833Hz = 0.0012s). I just realized getTime() was actually returning million seconds (Correct me if I am wrong), the speed is actually very fast if the value that return is ms. (500-1000 times fast than the data generated).
I am concerning if that's my IMU's configuration, I will double-check that.
However, when I decrease the speed to 52Hz or 26 Hz, the data was actually generated properly. and when I optimize the code, a couple more correct data set will appear before it gets messed up.
Not really sure what might be the issue now.
var t = getTime(); var elapsed = 0; console.log( "start of SPI call " + (getTime()-t) + " " + t ); //extraction(); omx = read_FIFO(ss); elapsed = getTime()-t; console.log( "elapsed " + elapsed );
And the corresponding output is:
start of SPI call 0.00700378417 946685774.25032615661 elapsed 0.01593494415
Enable extraction and disable read_FIFO() in the code
start of SPI call 0.00715160369 946686294.47058963775 elapsed 0.02543163299
The code to run one complete extraction() with no print
var t = getTime(); var elapsed = 0; console.log( "start of SPI call " + (getTime()-t) + " " + t ); function extraction() { omx = read_FIFO(ss), omy = read_FIFO(ss), omz = read_FIFO(ss), ax = read_FIFO(ss), ay = read_FIFO(ss), az = read_FIFO(ss), temp = read_normal(ss), tm = readtime(ss) } extraction(); elapsed = getTime()-t; console.log( "elapsed " + elapsed );
Output
start of SPI call 0.00709629058 946686935.69506931304 elapsed 0.04530811309
Here is my read_FIFO code, I am calling two SPI_read in this function, FIFO_DATA_OUT_H/L are two registers to store the generated FIFO data
function read_FIFO(ss) { return signshort(SPI_read(FIFO_DATA_OUT_H,ss)<<8|SPI_read(FIFO_DATA_OUT_L,ss)); }
Thank you very much.
-
Hi Robin,
Thank you very for replying and helping.
I set them to setInterval and that error does not occur anymore.
I believe I am using the hardware SPI and this is my SPI set up
function SPI_setup() { SPI1.setup ({sck:A5, miso:A6, mosi:A7, baud: 10000000, mode: 0, order:'msb', bits:8 }); }
The read time is to read the timestampes from the IMU, which is part of the data collection from the IMU.
the readtime Code looks like this:function readtime(ss) { hi = SPI_read(FIFO_DATA_OUT_L,ss); hi2 = SPI_read(FIFO_DATA_OUT_H,ss); non = SPI_read(FIFO_DATA_OUT_L,ss); lo = SPI_read(FIFO_DATA_OUT_H,ss); step = SPI_read(FIFO_DATA_OUT_L,ss); step = SPI_read(FIFO_DATA_OUT_H,ss); hi2 = hi2 << 16; hi = hi << 8; Value = hi2 | hi | lo; return Value; }
I checked the time needed to collect one set of data is fixed at .029ms, IMU generate each set of data at 833Hz = 1/833 ~=0.0012, the time for the IMU to generate one set the data is a lot faster than the program excution. I think the problem is when the FIFO is full, the pattern will be messed up.
I am not very sure why PICO takes so long to read a set of data. I tried to look up the default system clock rate and it seems 84MHz already based on this E.setClock(Correct me if I am wrong), is there a way to improve the program execution/reading speed?
Changed version code
function extraction() { st = getTime(); s2 = SPI_read(FIFO_STATUS2,ss); if(((s2)&0b00010000) != 0b00010000) { console.log( omx = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_L,ss), omy = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_L,ss), omz = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_L,ss), ax = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_L,ss), ay = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_L,ss), az = read_FIFO(FIFO_DATA_OUT_H,FIFO_DATA_OUT_L,ss), temp = read_FIFO(TEMP_OUT_H, TEMP_OUT_L, ss), tm = readtime(ss), getTime()-st); } } setInterval(extraction,0.00000000001);
Output:
///////////////The last number is the excution time////////////// 8273 -829 -15075 -77 -53 4231 -562 7840166 0.02954864501 6509 -2139 -9095 -88 -57 4253 -513 7840215 0.02941513061 5273 -2745 -8939 -86 -61 4244 -548 7840264 0.02940368652 4831 -2701 -8543 -84 -57 4250 -548 7840312 0.02936649322 4447 -2693 -8315 -89 -64 4251 -553 7840361 0.02934265136 4105 -2713 -7793 -85 -55 4250 -527 7840409 0.02941608428 3779 -2715 -6983 -86 -63 4240 -541 7840458 0.02939796447 3465 -2695 -5959 -90 -56 4245 -542 7840506 0.02937698364 ////////////Data start to have wrong pattern////////////// ////////////Data start to have wrong pattern////////////// 3191 -2637 343 -267 -337 -45 -548 16699391 0.02938270568 -21 21 53 -9 255 43 -548 5888 0.02933788299 29 21 3 17 5 17 -541 4864 0.02938842773 -249 9 15 255 5 15 -535 4352 0.02937221527
Spi:
function SPI_write(addr,data,ss) { SPI1.send([WRITE|addr,data],ss); //write to address } function SPI_read(addr,ss) { result=SPI1.send([addr|READ,0x00],ss)[1]; return result; }
-
I check the setTimeout method in this case based on this link, but due to the project requirement, I would prefer reading the data without any interruption for hours (with setTimeout, the code pause about at around 20s automatically with no error), I am wondering if there is a way to do it without pause the program?
Or Does Espruino Pico support this kind of application?
Thanks
-
Thanks to y'all help, I am making a lot of progress now. The code all seem working, but I am encountering this error "Prompt not detected - upload failed. Trying to recover..." when I run a long while loop in Espruino. I am trying to extract the FIFO data from the IMU(LSM6DSL) continuously for a long time. The data look correct at the beginning but the pattern got messed up after a couple of sets of data and then this error "Prompt not detected - upload failed. Trying to recover..." occurs and the entire program just stops.
Does anyone have any ideas of why this would happen and how to fix this? Thank you very much for y'all help.Figure 1 While loop code
Figure 2 Correct data pattern before the first 7th set. The number in the middle indicates the number of data left in the FIFO (2048 is when its full), it seems SPI is reading too slow to catch up the FIFO data generator, but I actually set SPI transmission rate to 10 MHz(max rate that the IMU can torrent), I would expect the SPI speed is sufficient enough.
Sorry the print title does not match up with the actual data, the correct order should be "gyro x ,gyro y,gyro z, acceleration x, acceleration y, acceleration z,temperature, timestamps"Figure 3 shows the error I am getting and the program crashed.
-
Hi all,
I am fairly new to javascript and Espruino.
I just started to implement the SPI, but the code does not seem to recognize my SPI. write function. I think it was because some header files were missing, but I am not sure what and how to include them.
Except for the SPI, I am having some trouble finding these function's library
function to convert decimal to binary
fopen,fclose -- (file open, file write, file close)
getTimeThank you very much for your time
-
-
Thank you very much for your reply.
I am making a PCB schematic based on this schematic and I am trying to make pins like: A8,B15,B14,B13,B12 as the SPI's CS pins and connect them to the slaves(taking to several slaves). I am wondering if I can set these pins low and high so that it can function as the CS pins?
In the schematic, these pins are not connected and the datasheet said most of those pins can be configured as anything.
I am wondering if you that the Web IDE allows me to configure these pins ? Thank you
-
-
Hi AkosLukacs,
Thank you for your help.
Sorry that I did not make the question very clear, I am trying to use SPI to be the communication protocol.
and I am having some issue using the Espruino Javascript library to read and write the register.Thank you
-
Hi
I am trying to use Espruino Pico to extract data from the IMU(LSM6DSL). In order to configure the IMU, I need to configure by writing and reading the value to the register. However, from the espruino library, I am not very certain how to write and read the value to the IMU registers. I am wondering if anyone has done something similar? Thank you very much for your help.
HI Gordon,
Thank you for your information.
It seems SWD can be connected using wires, correct me if I am wrong. I am wondering what role st-link play in this case
Thanks