Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

SPI bit order wrong?

SPI N+2

  • Please log in to reply
6 replies to this topic

#1 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 21 January 2013 - 05:44 AM

I am not sure as I'll die, but something strange is happening on my Netduino Plus 2 (firmware v4.2.1.2).

 

The demo program I'm using worked fine for several days, along many many IDE sessions. In particular I am talking about the bit order used out of the MOSI pin of the SPI. All the time it was (correctly) LSB-first, that is bit #0 first.

 

Today morning I started the same app, but unexpectedly the SPI outputs the MSB first. Any retry will lead the same result. Also checked with the scope, of course.

 

First question: anyone experienced anything similar?

Second question: is there anywhere the ability to configure this parameter and I missed it? Although the "original SPI" should always use LSB-first.

Third question: I will try to upgrade the firmware to the latest release, but...is that involved or, Chris, could you check whether this issue is still present in the 4.2.2?

 

NOTE: I could reflash my board, but I'd keep the issue for a while, just for inspecting where the problem is.

 

Any suggestion/comment is welcome.

Cheers


Biggest fault of Netduino? It runs by electricity.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 21 January 2013 - 12:58 PM

Hi Mario, What changed between the time when you were getting MSB data and the time when you were getting LSB data. That is a very strange observation indeed. NETMF should always output data the same way. Chris

#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 21 January 2013 - 01:28 PM

Hello Chris.

Well, I could bet nothing was changed in the source code. By the way, I really would not *how* to change that setting.

 

This time I really can't say that I mixed MF 4.1 and 4.2, because this project is and will be available only for N+2.

 

As you remember, I performed some tests with the unsafe code, but anytime the board has been reflashed (due forced hang-up).

However, the board has been plugged, unplugged, reset and whatever else, many many times.

 

Today morning I literally shocked by seeing the bits shifted out in the wrong order.

Once at home, I'll dig a bit more about this problem.

Cheers


Biggest fault of Netduino? It runs by electricity.

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 21 January 2013 - 01:44 PM

I am sorry, but in the below code when the LSBFIRST flag is set?

http://netmf4stm32.c...I_functions.cpp

 

Here seems the register table reference:

http://dics.voicecon...apter/SPI Setup

 

It seems to me that every time the SPI shifts out the MSB first, instead.

 

Am I watching the wrong place?


Biggest fault of Netduino? It runs by electricity.

#5 Hugo145

Hugo145

    New Member

  • Members
  • Pip
  • 7 posts

Posted 21 January 2013 - 03:09 PM

Hello Mario.

I'm using MF 4.1 and can confirm that SPI definitely shifts data MSB-first by default.



#6 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 21 January 2013 - 03:58 PM

My head is now totally confused, so...yes, I confirm the correct way is MSB first.

However this changes partially the problem because the program worked "fine" until yesterday, with the SPI shifting out the LSB first.

 

My apologies for the confusion, but I want to understand what's going on.

Cheers


Biggest fault of Netduino? It runs by electricity.

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 22 January 2013 - 04:55 AM

So...here is the story.

 

There is a program "A" as prototype using the SPI. This program worked perfectly many times (reflash, reset, unplug) with the SPI shifting out the LSB first: the code clearly show that. 

It's me, as my distraction, that I believed the LSB should going out as first, but it is not so.

 

At a certain point, since the prototype "A" is satisfying, I copied (not moved) the whole solution folder to a better place and organized the project sources as libraries. Let's call this new program as "B".

Once run, the program "B" shows the problem, because the sources are from the original program "A". However, the program "B" actually works correctly, shifting out the MSB first. I must changed the sources (still untouched since the original) and the program "B" gives a correct result.

 

Retrieve back the program "A": remember? It worked fine.

When run is not working anymore, just because the same reason of the program "B": the SPI now works correctly.

 

Well, so...I am pretty sure that the SPI worked wrongly for a period of time, but I really can't repro the behavior...

In the meantime forget this thread.

Cheers


Biggest fault of Netduino? It runs by electricity.





Also tagged with one or more of these keywords: SPI, N+2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.