Data exchange problem

Nope. :stuck_out_tongue: thuis is the board:


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:

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:
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…
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 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 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][/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:

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… that way I can actually do end2end testing on the CAN bus between my Panda2 and the CWX. I’ll get some RS485 transceivers at the same time to test that route.