SPI question #548
Replies: 31 comments
-
Posted at 2014-07-29 by @gfwilliams I think there are two main issues here:
Otherwise it's doing what you expect - C0 will be taken low, data clocked in/out, and then C0 is taken high again. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-29 by user7143 Thanks Gordon. I now am receiving data. The chip was a Max 31855 used to measure thermocouple temperature. I will share code to add to modules when I have it working. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-29 by user7143 Strange I had it working for about 1 minute and then it stopped working. I hooked up a logic analyzer and it does not send 32 clock cycles. Seems to send a few then stop and then send a few more. I know the chip is working as I am also running it on a different kind of micro controller. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-29 by @gfwilliams How exactly is it not working? It's unlikely that something would have just happened after 1 minute... are you sure it's not just a bad connection? I just checked and it seems that at 1mbps it's having trouble keeping the 1 byte SPI buffer full. To be honest it shouldn't really be having problems with that - I'll have to look into why. However I'd be very surprised if that was the problem. That's why there's a clock and a CS line after all. If you do really want an unbroken clock signal your other options are to just lower the baud rate (500000 seems to work fine) or to switch to sending/receiving Strings, which are a bit faster to access:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-29 by user7143 I have confirmed that the 32 clock cycles are now sent on the sck line. The CS line is also working. However the MISO line reports all 255's which is not right. It's not the chip so something strange going on. I will try to get the STM discovery upgraded to report if it has the same behavior. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-30 by user7143 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-30 by @gfwilliams Just uploaded for arran:Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-30 by @gfwilliams Have you updated the SPI initialisation code to initialise B4 to miso? In the original code you gave, you don't do that. If you specify some SPI pins but not others, only the SPI pins that you specify get set up - and if you don't specify an input then it'll probably just read 1s in - regardless of what the actual input is doing. In the graph you sent, I don't see any data coming from the chip. Is that intentional? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-30 by @gfwilliams If the chip isn't sending data, is it that it's expecting a 5v signal? That shouldn't be an issue, but I'm struggling to see what the issue could be. Also you said that it was originally working with Espruino, and then stopped? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-30 by user7143 Finally got it to work! Not sure what the problem was as I unsoldered everything and reassembled it. I was able to get output from the chip if I connected the logic analyzer to the pin of the chip before I disassembled. So I suspect it was a dry joint or something hardware related. Gordon thanks for your help. Will send you the code to add to modules when it is completed. Next job is to add a pressure transducer to the board. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by user7143 Gordon, Thanks for your help. Here is the code to interface espruino to a max31855 chip. The max31855 is connected to a thermocouple to measure high temperature up to 1300C. Feel free to use it to create a new module for Espruino.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by DrAzzy Modularized. I posted the module - does this work?
Module code:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by possmann @drazzy: just a little code review question: why do you store this.spi / this.cs inside the constructor? And why not use this.spi / this.cs in the getTemp? I would have expected this:
Otherwise i don't understand the constructor. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by @gfwilliams Nice, thanks both of you! I've got an Espruino car ECU project and I always wanted to be able to log the exhaust temperature. It glows cherry red so it'd melt most stuff - I'll have to have a look at this and see if I can rig something up :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by @gfwilliams @possmann: I think it might have been a mistake :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by @gfwilliams You could just look in a scrap yard? I'm measuring vacuum, but the GM sensors are great. 5v in and a basically 5v swing on the analog output. I'd guess the ones off turbo cars are very similar |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by user7143 Thank you for putting this code into a module. I have been trying to understand OOP Javascript and just brought a book to try to wrap my head around it. Looking over this code as well as the comment from possman, It now fairly clear the way it works. Having scratched my head over this for a couple of weeks and now the light bulb in my brain turns on! I did try the code and it partially works. It does report temperature correctly but the error reporting does not work correctly now. It only reports case 4 under all fault conditions. I will try to debug this and repost code later today. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by user7143 I have a old VW TDI that I have been experimenting with. Interestingly from my research they don't have a turbo pressure boost sensor, if they had it would be easiest just to tap directly into the sensor or the CAN network. It think that they calculate boost pressure using RPM and mass air flow sensor. Ideally the easiest way to do this would have been to connect to the CAN and get boost pressure if VW had a boost sensor on the motor. I was able to do this on a Caterpillar large diesel engine using javascript and npm Can on a Beaglebone Black. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by user7143 This seems to have fixed the fault reporting issue.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by DrAzzy Oh, I see. I was doing switch/case wrong, and left out the breaks. I always forget the syntax for switch/case.
Should now return an object with properties temp (the temperature), fault (the fault code) and faultstring (with a description of the error condition, if available). Version on my website updated, so this should work:
I'll be submitting this module if it works - want me to credit you as something more, ah, personal than "User7341"? :-P |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-31 by possmann Just a little enhancement to reduce the code size: i guess its unnecessary to define the var fault. You stored the information in the object (see line 17.) why not use the object as default?
and you can combine these lines:
Sorry, to be a little bit niggling :-) Memory is a limited resource! (it's hard to say this in a time of 2014) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-01 by DrAzzy Thanks, updated per your suggestion. If this works (I can't test - I don't have one of the chips on hand), I'll make a pull request this weekend. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-01 by user7143 I will test tomorrow but still think a couple of changes need to be made.
This will allow more than one temp sensor to be connected and report temperature. The else statement needs to be added back in at the end. See my code above. The reason for this is you only want the temperature reported if everything is ok. If a fault code is displayed then you only want that code. If not you get the fault code as well as a incorrect temperature reading. Once this is done I will test again and let you know if it works. Really glad that I shared this code as I learnt a lot about OOP javascript today from everyones responses. Even though I have been reading a really good book on the subject, this thread really helped to cement all the pieces in place. So thank you to all who responded. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-01 by user7143 I tried out the code and it sort of works! The only problem with including trtn.temp and trtn.fault in the same variable is the way the chip works. It supplies a 14 bit word that has temperature and fault information. Therefore when the fault flag is raised it still gives a temperature, just the wrong temperature. I included the if else statement in the earlier code to account for this. Maybe someone can suggest a way to accomplish with the trtn.temp and trtn.falut included in the same variable. {"temp":2047.75,"fault":1, see the example above where no probe is detected yet the temperature is reported back as 2047.75C. Ideally I think what is needed for simple example temperature measurement is the correct temperature or the fault condition. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-04 by DrAzzy Updated on my site. Code is:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-04 by possmann SPI1 should be this.spi :-) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-04 by user7143 I tested and this code works. Just need to change one last item that Possmann stated above and its ready to be added to the modules. I spent some time working with I2C over the weekend and can provide a couple of other temperature modules to post soon. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-04 by @gfwilliams Great! It's already done! https://github.com/espruino/EspruinoDocs/blob/master/devices/MAX31855.js It'll go live next time I update the website... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-04 by possmann It is really a good idea, to return an error message string instead of an error code? I guess thois could safe some memory and performance. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-04 by @gfwilliams I'm not sure it's such a big worry here. One nice improvement would be to define the error strings in an array: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-28 by user7143
I am trying to write code to connect a chip to the espruino but am really not getting how it works! I want to figure it out on my own but need some help. Hence the fact I am not stating what chip I am trying to interface too.
The chip has three lines SCK, MISO, and CS.
So I connect SCK to B3(sck on espruino), MISO to B5(miso on espruino)
CS is connected to C0
In the command line I write the following commands
///
///
The device should send back a 32 bit number.
From my understanding reading the datasheet once the cs goes low the chip should start writing data to the espruino as the sck signal starts. Can anyone offer some pointers or explain the error in my understanding of SPI.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions