Data exchange problem

Nope. :stuck_out_tongue: thuis is the board:

[url]http://search.digikey.com/us/en/products/MCP2515DM-PTPLS/MCP2515DM-PTPLS-ND/1999509[/url]

I just got word that the Sparkfun CAN adapter is in the mail so I wonā€™t be ordering the one from digi. Itā€™s the same chip though so it shouldnā€™t make a difference. I actually prefer it this way as the Sparkfun module comes with a MicroSD adapter, connector for a GPS module and a serial data display connector at a lower price than the digi board.

Iā€™m expecting it to arrive either Friday (if Iā€™m very lucky) or early next week. Hopefully Iā€™ll be able to figure out something that might help youā€¦

Iā€™m just curious why you insist on using CAN for the data exchange since from what I figured both CWX and Panda2 can do RS485 over the serial port and there is also RLP code available for that. Do you have a specific need to use CAN over RS485 (cable lenght maybe)?

Hi Xycon,

In fact Iā€™m considering to switch to RS485 for now, but I still donā€™t understand the basics of working with RS485. I just figured out CAN, seems like a waste of time when I switch to RS485 nowā€¦

What I would like to know is how the diffrent devices on the RS485 bus know when to talk and when to shut up. Do I have to implement some chipselect mechanism or is there something foreseen in the controllers?

I have received some tranceivers for RS485 and the other stuff should be here somewhere as wel.

I tried googling about RS485, but found more questions than answers.
If you know about some good documentation let me know.

Anyway, I ordered a barometic pressure sensor and an accelerometer, both equiped with SPI and neither of them is working with ChipWorkx. I get it to work on Fez without problems, but no way on CWX. Iā€™m getting a bit frustrated with this.

Iā€™m sure itā€™s something I do wrong, but I canā€™t figure it out. Surely, if there was something wrong with SPI on CWX, some else must have noticed this also?

Iā€™m considering starting a new thread just about SPI on CWX. Maybe tomorrow.

Just to let you know I finally got all the material I ordered. Iā€™ll be doing some tests this evening and let you know about as soon as possibleā€¦

The CAN-Shield I recieved from SparkFun (through Lextronic) is actually an Arduino style shield, so it fits nicely on the Panda2 I got along with the shield. Obviously itā€™s stupid though since the Panda2 already has two CAN ports and a MicroSD slot so adding another CAN port (even though the shield actually comes with a transciever which the Panda2 doesnā€™t have) doesnā€™t make a lot of sense. The only things of interest for the Panda2 would be the Joystick button (though it takes 4 analog ports!) and the connector for the GPS module (which I donā€™t have).

Well itā€™s still a nice thing as Iā€™ve actually been thinking of creating a little addon board for the CWX that can take Arduino style shields. It would need an ADC/DAC and some voltage converters to make sure no 5V signal arrives at the CWX but other than that it shouldnā€™t be too difficult. Maybe it could even have some slots for Gadgetter and eblock modules. Iā€™m actually hoping a bit that GHI might pick up this idea and offer such a board themselves. Now that Iā€™m thinking about itā€¦ wasnā€™t there actually an announcement of something like this being developed?

Either way I have connected the shield to the CWX now and ran your program. Attached is a screenshot from my Logic Analyzer though itā€™s not as powerful as yours. Iā€™m wondering why I donā€™t see anything on MISO.

I think before I continue with the shield I will do some more basic tests with SPI (I havenā€™t worked with it at all yet) as you mentioned it wasnā€™t working for you.
I actually got a SparkFun BusPirate with my latest order so I should be able to easily send SPI messages back and forth with that thing. Iā€™ll let you know how that works outā€¦ maybe this will help find the SPI problems youā€™ve been talking about.

One more thing about the shield, unfortunately it doesnā€™t break out the CAN_TX and CAN_RX data but only the CAN_L and CAN_H after going through the MCP2551, so Iā€™m not yet sure I can connect it to the Panda2 without getting another transciever. Iā€™m still hoping I can grab the data right from the chip but Iā€™ll try that after the basic SPI testing sessionā€¦

There is can on panda do why ate you adding MCP2515?

:think: Autocorrect again? :slight_smile:

Lol. I seriously need to stop using this freakin phone lol :wall:

Or disable autocorrect. :wink:

Iā€™m not! I now have a Panda2 and the CWX, and Iā€™m looking at different ways of having them communicate with each other. Since SPI and I2C wouldnā€™t work as they are both masters, that would leave only uart since CWX doesnā€™t have CAN onboard. However since NickS is trying to interconnect his Cobras with the CWX via CAN bus, I thought that might be an interesting solution since uart isnā€™t a bus protocol where you could have three or more devices on the same bus.

When looking for a suitable board with the MCP2515 chip, I found the SparkFun CAN-Shield which is slightly cheaper as the ā€œofficialā€ Microchip board and has some extras on top of it like the MicroSD slot, Joystick etc. It is designed as an Arduino type shield so of course it would work well with the Panda2 but as I already wrote it isnā€™t really useful because most of the shield functionality is already on the Panda onboard.

So the plan is to use the shield with the CWX to add CAN capabilities to it and have it communicate with my Panda2 and NickSā€™ Cobra. Thatā€™s when I got the idea to design a board for the CWX that allows to connect shields to itā€¦ to combine the power of CWX with the expansion capabilities of Arduino inspired boards and also add connectors for Gadgeteer and eblock modules. I think I remember reading about some plans of having an official GHI board produced for that, which Iā€™d buy immediately.

Back to the topic, unfortunately the BUS pirate only works as an SPI master and not as a slave, so the only two SPI slave capable devices I have right now is that CAN/MCP2515 module and a CY8C29466 chip that I also bought from SparkFun. However that CY8C29466 is a complicated thing and I havenā€™t completely figured out how to program that thing through the CWXā€¦ it was intended to be a project for the x-mas holidays anyways.

So I really only have the CAN shield for SPI testing right now. Iā€™ll try to go by another electronics store next week to see if I can pick up anything interesting supporting SPI but until then I guess my best way to help out with this is to look into the RS485 which might be an alternative to using CAN for interconnecting our devices. From what I understood the CWX can do RS485 directly without any additional hardware through the onboard MAX232 chip. Iā€™m not sure the Cobra has this chip on board as wellā€¦ the Panda2 doesnā€™t. I have one very old Max3243ECAI chip where I donā€™t even know if it still works and if he supports RS485 so Iā€™ll check that out first and if needed will pick up another 232 next week as well.

@ NickS what are the transceivers you bought for RS485? Iā€™m not sure theyā€™re actually needed but if they are it would be good if we use the same :slight_smile:

LOL I actually just found out that I do have another SPI slave chipā€¦ a digital Pontiometer that was part of my last order: http://tinyurl.com/bu526su

The problem with this one though is that it has MISO and MOSI multiplexed on the same pin with a ā€œsmartā€ pull-up resistor. Itā€™s actually consistent with my logic analyzer which also only uses one pin for SPI Data (I was wondering earlier why it didnā€™t have two ports for MOSI and MISO). Now I just have to figure out how to do the proper cabling for the chip to work with the CWXā€¦ but since itā€™s 4am now this will have to wait for tomorrowā€¦
If anyone can give me a hint about this multiplexing, here is the datasheet: http://tinyurl.com/d4q7uvy
It seems there is only a resistor needed between the two pins but they donā€™t seem to give a value other than saying that it ā€œmust be sized to ensure VIL and VIH of the devices are metā€ ā€¦ :o

Finally there is also one more thing I could use for SPI testingā€¦ http://tinyurl.com/d4kjuj7
Instead of plugging it into the slot I could directly cable it to the SPI port and try to program it manuallyā€¦ though Iā€™m not sure how easy that will beā€¦

After I found a nice C implementation of the MCP4131 chip I decided to simply port it instead of writing my own code ::slight_smile: I havenā€™t had a chance yet to trace the SPI bus to see what is actually being transferred, but my LED is nicely fading in and out with this code.

Iā€™ll be posting the bus traces and some more detailed output as soon as possible. For now, here is my code for the chip:

UPDATE: I have posted the now working code on http://code.tinyclr.com/project/406/mcp4131-digital-spi-potentiometer/ and removed it from here.

When you use mutibyte commands (settap, readtap), you will have to send them as an array, not as separate byte transfers. The .NETMF SPI implementation releases the select line after each transfer, so for multibyte commands and reads, you will have to use byte arrays to avoid the command being ā€œchoppedā€ (or else do the select line manually with an IO pin).
Could this be the problem?

Thanks for the tip. I changed my code to use the CS pin manually but that didnā€™t change anything. On the other hand I also checked with my logic analyzer and it seems I have the same signal on MOSI and MISO. According to my research ā€œ[italic]SDO is connected to a 4.7K resitor before it connect to the shared SDI/SDO Pin[/italic]ā€ but that somehow doesnā€™t seem to work yet. Iā€™ll keep working on this but I guess this chip isnā€™t the best way to troubleshoot this general CWX SPI problem we are suspecting. I guess Iā€™ll get back to the CAN shield for now.

UPDATE: I got the POT to read/write once I switched from 3.3V to 5V using the Panda2 (which thankfully supports 5V input). So either Iā€™ll have to find the correct resistor value for 3.3 supply voltage (I tried all the resistors I had and none seem to work) or use a converter to try the same thing on the CWX. Btw using the manual control for the cs_pin was still necessary to use the source code as above. I guess Iā€™ll have to rewrite the code to send both bytes in a single WriteRead command.

I made several updates in this last posting

I updated the source code which now works correctly reading the values (at least when I use 5V). I have posted it in the code section on http://code.tinyclr.com/project/406/mcp4131-digital-spi-potentiometer/. I donā€™t think a Wiki entry is necessary because itā€™s not that interesting of a chip.

Monday Iā€™ll go on vacation for 10 days. My plan is to only take the CWX and a JTAG module to continue working on RLP and Linux. Maybe Iā€™ll finally manage to get the LCD output workingā€¦

Iā€™m not sure Iā€™ll be ordering a Hydra since I donā€™t see any real need for it since I already have the CWX . The only interesting part would be the fact that itā€™s 100% open source. Shipping cost is $60+ and once it arrives Iā€™ll still have to pay 20% taxes on top of that and 10ā‚¬ for FedEx to collect the taxes. This means even if I decide to buy it I wonā€™t order it from GHI but will wait that Lextronic in France or another European distributor has it in stock. Iā€™m still hoping that GHI will also release sources of their older modules. If I could switch between GHI and JTAG mode on the Panda2 for example it would be really helpful and I wonā€™t have to use two different boards that would essentially both do the same thing except one having a special firmware.
Unlike my earlier plans I wonā€™t be taking any external hardware with me as I donā€™t have any space left to pack it securely (Iā€™ll travel by train so luggage is limited).

If all goes well Iā€™ll be back on the 28th to continue working on these issues. I hope to be updating my blog and the Linux thread with some news until then.

Update: I finally got the thing to work with 3.3V logic level on the SPI interface. I hadnā€™t realized that those Sparkfun logic level converters ([url]http://tinyurl.com/4unr96h[/url]) only have 2 bi-directional ports and Iā€™d be needing two modules for SPI. Iā€™ll plan to get some of these instead with my next Sparkfun order: http://tinyurl.com/7j8fmr6

On the ChipWorkX I donā€™t get absolute values for the wiper but only values of 0, 1, 3, 7, 15, 31, 63 etc. I have previously seen this on the Panda2 as well but after adding a 2nd resistor for MISO the problem was gone. The values for TCON and StatusREG are exactly the same as on the Panda2.

All in all I think this proves that at least this simple SPI slave chip is working correctly with the CWX. I will still try to figure out this odd Wiper bug but since I got this issue on both Panda2 and CWX itā€™s obviously just a question of correctly de-multiplexing the data lines for the SPI bus. If anyone has any idea how to enhance this Iā€™d be happy to try suggestions. I tried posting a comment on SparkFun but it gives me an error telling me Iā€™m not logged in although I am.

I made several updates in the posting above. I got the pot to work more or less on the CWX so thatā€™s the first working SPI slave chip I testing sucessfully on the dev board.

Iā€™ll have to start packing my bags now and prepare for the x-mas vacation with my parents. Iā€™m not sure Iā€™ll have any chance to post before Iā€™m back on the 28th so I already wish everyone happy holidays and a merry x-mas!. I hope Iā€™ll have some news regarding Linux on the CWX once Iā€™m backā€¦

As for the CAN shield, I set it up with the two voltage regulator modules and added some Debug.Print lines to the code. It seems at least for now the SPI read commands work (I always get 255). I have attached my slightly modified code with the debug messages. Maybe theyā€™ll help you a bit and you can add more of them where needed. I personally prefer this type of debugging over stepping through the code.
When I tried the same setup on the Panda2 with the voltage converters I got the same behavior getting 255 on every read. I have then connected the Panda2 directly with the voltage converters and got 128 instead (Iā€™m not sure if thatā€™s any better though).

Sorry I donā€™t have any more time now because I have to really start preparing for my travelā€¦ As I said Iā€™ll be back on the 28th and will continue with this problem asap. Maybe during this time you could try my code and post your output and possibly add some more Debug lines to see what is supposed to be transmitted over the SPI interface and then verify it with the logic analyzer.

This is the output Iā€™m getting on the CWX:
Starting the CAN module
Read: 255 from Address: 14
Wrote 7 to Address: 15
Read: 255 from Address: 14
CAN module set to normal operation

Transmitting MSG: 85 Length(2)
204 170

Wrote 10 to Address: 49
Wrote 160 to Address: 50
Wrote 2 to Address: 53
Read: 255 from Address: 44
Read: 255 from Address: 44
Read: 255 from Address: 96
Read: 255 from Address: 97
Read: 255 from Address: 98
Read: 255 from Address: 99
Read: 255 from Address: 100
Read: 255 from Address: 101

Received MSG: 536870911 Length(15)
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255


Transmitting MSG: 85 Length(2)
204 170

Same code but without voltage converters on the Panda2:

Starting the CAN module
Read: 128 from Address: 14
Wrote 7 to Address: 15
Read: 0 from Address: 14
CAN module set to normal operation

Transmitting MSG: 85 Length(2)
204 170

Wrote 10 to Address: 49
Wrote 160 to Address: 50
Wrote 2 to Address: 53
Read: 128 from Address: 44
Read: 128 from Address: 44
Read: 128 from Address: 44
Read: 128 from Address: 44
Read: 128 from Address: 44
Read: 128 from Address: 44

Transmitting MSG: 85 Length(2)
204 170

Any news from your side? As you can see in the other topic I got another SPI chip to work on the CWX, this time an ADC although I havenā€™t compared the output to the Panda2 yet but at least that chip gives me the data Iā€™m expecting.

I found some CAN transceivers in DIP format on Digikey so Iā€™ll get some next weekā€¦ http://tinyurl.com/75zh5ck that way I can actually do end2end testing on the CAN bus between my Panda2 and the CWX. Iā€™ll get some RS485 transceivers http://tinyurl.com/6vvqy8d at the same time to test that route.