Netduino Plus 2, SPI not working, .NET Toolbox, - Page 2 - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
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

Netduino Plus 2, SPI not working, .NET Toolbox,


  • Please log in to reply
44 replies to this topic

#21 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 January 2013 - 07:56 AM

Just FYI...we're working on a 4.2.1.3 update which will include SPI enhancements to the STM32 core.

 

Chris



#22 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 01 January 2013 - 08:01 AM

Awesome.  Do you happen to know if this would also be the reason my serial 7 segment display is displaying garbage?  The following code worked with a NP, but show random characters when connected to the NP2. 

 

device = new SPI.Configuration(

Pin, // SS-pin

false, // SS-pin active state

0, // The setup time for the SS port

0, // The hold time for the SS port

false, // The idle state of the clock

true, // The sampling clock edge

250, // The SPI clock rate in KHz

SPI_Devices.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset)

);

 

Again, it's been so long since I've wired these things up that I can't be sure.  If the settings below don't work because of the problems you're working on, do you happen to know some other settings that will work for this display?  I found the following in a manual, but I'm not sure what I could change to work around the bug...

 

SPI Communication

When using SPI to communicate with the display three wires are used - SDI (slave data in, aka MOSI), SS (slave select), and SCK (serial clock). SS selects the display in a multiple slave SPI bus. SCK is the serial data clock, an input to the display. And SDI is the data input line, also an input on the display.

The Serial 7-Segment display is configured to act as a SPI slave device.

The maximum speed of the SPI clock input is 250kHz. The display is configured to work with SPI mode 0 (CPOL = 0, CPHA = 0); the clock line should idle low, and data is sampled on the rising edge of the clock.



#23 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 January 2013 - 09:25 AM

John, in order to make the HC595 regardless some "bug", you should use this configuration:

 

 

 

 

device = new SPI.Configuration(Pin, // SS-pinfalse, // SS-pin active state0, // The setup time for the SS port0, // The hold time for the SS porttrue, // The idle state of the clock (any, but "true" is often better)true, // The sampling clock edge (must be true for 74HC595)250, // The SPI clock rate in KHzSPI_Devices.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset));

 

 

The "idle" value might be whatever if you are using the SPI just for driving HC595s. However, if you are using other logic on the same SPI and/or the SPI port open/closes in your program, you should choose that value to best fitting the hardware constraints.
Furthermore, consider than there's *no* pull-up on the N+2, so you should provide one for any I/O. That is mandatory whereas an I/O is not configured as an output. As stated above, until you use the SPI, you are guaranteed to have SCK, MOSI and the optional SS as outputs, while MISO is an input and should be tied to +Vdd by a pull-up. As soon the SPI is closed/disposed, all of the pin become floating inputs and deserves a pull-up each.
In brief, on N+2 consider placing pull-up on most pins: the old N Atmes-based embeds them for you.
Cheers

Biggest fault of Netduino? It runs by electricity.

#24 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 01 January 2013 - 10:21 AM

The maximum speed of the SPI clock input is 250kHz. The display is configured to work with SPI mode 0 (CPOL = 0, CPHA = 0); the clock line should idle low, and data is sampled on the rising edge of the clock.

If my experience is anything to go by then you will not be able to get any sensible data out of the N+2 using SPI and the configuration quoted.  You should verify the data with a scope or LA (I know Mario prefers the scope).  If you look back in this thread you will find some screen captures which Mario kindly put together showing the various problems with SPI.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#25 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 01 January 2013 - 04:26 PM

Thanks.  Nevyn, I think you're right.  Mario, when I put idle state = true and clock edge = true, it's better, but still off.  With these settings, I'll get the first three characters showing, but nothing on the 4th.  And there will be garbage sometimes.  Also, I've never used a scope or LA (whatever that is) in my life.  I'm a software guy who knows just enough about electronics to get by.  Maybe I should buy a scope and learn it, though.

 

Mario, thanks for the help.  At least it got me close enough to know I wired things correctly.  As for pull-ups (that's a resistor, right?), if I only use SPI for output, am I ok without them?

 

Chris, why were embedded pull-ups removed?  Is there anything in a wiki anywhere about this change vs the NP that I can read to educate myself?

 

So I guess I'm going to have to wait for the bug fix to really be able to use the NP2.  I wish I had ordered NPs instead.  I love Netduinos, but this seems like a huge bug, and I'm really surprised this wasn't caught prior to release.

 

Thanks again for all the help!



#26 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 01 January 2013 - 04:41 PM

Sorry, LA = Logic Analyser.

 

I would not regret the purchase of the NP2, I am sure that Secret Labs will get the problem fixed and we will then be able to take advantage of the extra memory and speed,

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#27 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 01 January 2013 - 04:42 PM

Sorry, LA = Logic Analyser.

 

I would not regret the purchase of the NP2, I am sure that Secret Labs will get the problem fixed and we will then be able to take advantage of the extra memory and speed,

 

Regards,

Mark

 

True, except for the pull-up issue.  Hopefully Chris can point me to a wiki so I can understand this better.  Like I say, I'm still learning (and always will be).



#28 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 January 2013 - 05:43 PM

Pull-ups.

Yes, a "pull-up" is, as the name suggests, a resistor which "pulls" the voltage up toward the supply value. Why it needs? Because for an input it's important the voltage applied and leaving it "floating" (i.e. without any connection) it means the actual voltage it may be any value.

The pull-up has most of the times the only purpose to guarantee an high voltage level when no other voltage source can do it. Thus, even leaving an input "floating", the pull-up guarantees a certain logic level. Most of the times the preferred voltage is, as stated, the supply, thus the resistor is called "pull-up". Sometime you need the opposite: a resistor pulling the voltage toward ground and it's called "pull-down".

If you like a software analogy, it's much like declaring a variable.

 

 

int temp;int result = temp + 2;

 

AFAIK, in C/C++ its value is unpredictable until you explicitly assign some value to "temp", thus you cannot predict anything for "result".

In C# (that's for sure) you have two points: first off the "temp" is implicitly initialized to zero, however the compiler won't leave you use the variable "temp" without explicitly assign it.

 

The missing pull-ups in the Netduino Plus 2 is not a bug and surely not involving Chris. Instead, is a different design choice made by the ST engineers over the Atmel team.

In the old Netduino there are pull-ups for default, thus anytime an I/O is left open, it considers the logic to "high". Many users were blaming this behavior because, for instance, at power-on all the I/Os are configured as input (with pull-up). When they use the I/Os for a relay, it activates briefly on each board reset. This behavior won't happen in the Netduino Plus 2.

Who's right?

My viewpoint is that the Atmel choice is preferable. I would not leave an input "floating" anytime: when an I/O is not used there must be some "subject" granting me a certain level. So, the pull-ups are welcome. What the users are blaming against the relay activation is a "weakness" of their design (no hurt). The truth is relying on what the I/O actually need, only after I must deal with my own logic added to the board. Thus, I should design the relay interface accordingly so that any spurious activation will be avoided.

So, Chris done the right thing not adding *any* pull-up to the new board simply because the user "must" face with a different hardware, even the MF ability to abstract it is very nice.

 

 

Netduino Plus or Plus 2?

I agree with Mark: I own both and I am happy with them. As they were "sons": one is older and you know it better, another is still young and you should take care.

Because the more resources and the higher speed of the Plus 2, you'll be much more satisfied, IMHO.

The new born has still some problems to solve, but I believe they're fixed within some weeks.

 

 

LA/scope.

I would not buy any of them unless you are seriously thinking to deal with hardware.

The LA is a very useful tool specific for logic signals. Most of the time your circuits are built over logic voltages, states, messages, etc. If you plan to keep within this context, a LA might be enough.

If you want to deal with analog signals (e.g. audio, sensors, etc) and/or inspect deeper what's up with your electronic parts, a scope is mandatory.

If you like a software analogy, you can use Visual Studio for compile your C# program, but you might find useful seeing what's the real native code executed by the CPU.

 

 

Finally, your circuit.

Could you post the actual source of the program running?

 

Cheers


Biggest fault of Netduino? It runs by electricity.

#29 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 01 January 2013 - 06:58 PM

the stm32 has pullup and pulldown support, it just needs to be set in software.



#30 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 01 January 2013 - 09:56 PM

the stm32 has pullup and pulldown support, it just needs to be set in software.

 

Chris, it sounds like there might be a lack of consensus on whether the NP2 has pull-ups.  I'm the worst person to ask, since I understand the least, but can you elaborate?

 

Also, is there any way to get an early beta of some type for the update?  I'm literally stuck with non-working serial 7 segment displays until then.  Thx.



#31 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 January 2013 - 04:35 AM

the stm32 has pullup and pulldown support, it just needs to be set in software.

 

Uh, oh!...You're right: it's not a design choice by ST!

At this point Chris should decide.

 

-- after some search ---

P.S.: the ST specs are confused a little and not so exhaustive. However, the ST places all the I/O as analog input (without pull-up/down) during power-up. Even changing the behavior in firmware, what happens during the power-up is not overridable. At this point, I don't know whether anything can be changed *before* the bootstrap, otherwise the only way to patch this feature is adding real pull-ups externally.

 

 

-- a small test --

[color=#b22222;]WARNING:[/color] if you live in a pretty dry climate and/or you're dressing wool clothes, then your electrostatic energy may be relevant so that to damage the Netduino. If you're scared/unsure about that it's best if you avoid this test.
 

Try yourself:

 

 

 

    public class Program    {        static void port_OnInterrupt(uint data1, uint data2, DateTime time)        {            Debug.Print("interrupt");        }        public static void Main()        {            var port = new InterruptPort(Pins.GPIO_PIN_D1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);            port.OnInterrupt += new NativeEventHandler(port_OnInterrupt);            port.EnableInterrupt();            Thread.Sleep(Timeout.Infinite);        }    }

 

Connect a wire to the I/O #1 (the 2nd) and leave the other side floating, then run the program within the IDE and take a look at the "Output" pane.
Probably you don't see anything interesting. Now, touch briefly the wire with your finger: you should see a bunch of "interrupt" due to the events generated by the noise revealed at the I/O level.
This demonstrates how even a very very small energy (your finger) can lead to an unpredictable level to the input.
 
Hope it helps.
Cheers

Edited by Mario Vernari, 02 January 2013 - 06:46 AM.

Biggest fault of Netduino? It runs by electricity.

#32 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 02 January 2013 - 12:00 PM

Mario, You are the man!

 

I've had a few weird issue's with this floating stuff in the past and never really understood it. I have had a few circuits with oscillator's and timers where just the touch of a finger would alter the freq and I've just put it down to my incompetence. What a fantastic way to illustrate it.

 

Thankyou very much.



#33 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 02 January 2013 - 02:01 PM

Finally, your circuit.

Could you post the actual source of the program running?

 

Cheers

 

Unfortunately, I can't really post my source.  I've got multiple projects in my solution.  I'm doing a lot of abstraction where I can, and building something that gives me event-like programming.  I've got a scrolling message service that can scroll a msg on an lcd or a 4 digit 7 segment display, for example, without my main code having to know about what hardware I'm using.

 

With that said, I'm almost positive now that the problem is with the SPI, since 1) I got the 74hc595 working by changing the settings, and 2) the 4 digit 7 segment display works better than it did before by also altering spi settings.  Once I can make the settings what the manufacturer states are necessary, I should be good to go.



#34 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 January 2013 - 02:08 PM

Unfortunately, I can't really post my source.  I've got multiple projects in my solution.  I'm doing a lot of abstraction where I can, and building something that gives me event-like programming.  I've got a scrolling message service that can scroll a msg on an lcd or a 4 digit 7 segment display, for example, without my main code having to know about what hardware I'm using.

 

With that said, I'm almost positive now that the problem is with the SPI, since 1) I got the 74hc595 working by changing the settings, and 2) the 4 digit 7 segment display works better than it did before by also altering spi settings.  Once I can make the settings what the manufacturer states are necessary, I should be good to go.

 

I don't know if helps, but I already made such a library a while ago:

http://highfieldtale...y-for-netduino/

 

The most interesting thing is that runs very fast than other libs using just adding an inexpensive transistor. It also offers two kinds of interaction: imperative and declarative.

Another one is coming shortly, using a led-matrix as display.

Hope it helps.

Cheers


Biggest fault of Netduino? It runs by electricity.

#35 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 January 2013 - 07:35 AM

Quick update:

We dug in and analyzed the various clock idle and sampling edge settings, and found a few issues in the NETMF core BSP. We have fixed these in the new 4.2.2.1 release.

http://forums.netdui...-v422-update-1/

Two changes:
1. We now enable an internal pull-up on the SPI clock line so that it remains high until the clock starts going.
2. We reviewed and corrected the order in which SPI is configured to eliminate extraneous clock transitions.

For the users who were having troubles migrating their projects to Netduino Plus 2 because of SPI issues...please let us know if this fixes things for you.

One note: STM32 is way faster than SAM7X was. So if your target chip needs a bit of time to notice the SPI_SS signal, be sure to add setup (before transaction) and/or hold (after transaction) time in your SPI.Configuration. These values are measured in microseconds.

Chris

#36 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 26 January 2013 - 08:11 AM

Chris, thank you for the update and explanation. From my few tests, things seem to be working as expected.

 

One note: STM32 is way faster than SAM7X was. So if your target chip needs a bit of time to notice the SPI_SS signal, be sure to add setup (before transaction) and/or hold (after transaction) time in your SPI.Configuration. These values are measured in microseconds.

 

I tested a couple scenarios with the ChipSelect_SetupTime and ChipSelect_HoldTime. Anyone who's interested can find those results in this post:
SPI Configuration and the various Modes

 

Cheers,

Steve



#37 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 26 January 2013 - 10:25 AM

LA/scope. I would not buy any of them unless you are seriously thinking to deal with hardware. The LA is a very useful tool specific for logic signals. Most of the time your circuits are built over logic voltages, states, messages, etc. If you plan to keep within this context, a LA might be enough. If you want to deal with analog signals (e.g. audio, sensors, etc) and/or inspect deeper what's up with your electronic parts, a scope is mandatory. If you like a software analogy, you can use Visual Studio for compile your C# program, but you might find useful seeing what's the real native code executed by the CPU.

Can I ask which scope model you use?, I kinda like that you can take snapshots, I have been thinking about an Rigol or somehting, but not sure yet about which speed one need on it, to be able to take snaps of the signal traffic as you do here.

--
Asbjørn


#38 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 January 2013 - 06:15 PM

At home I have a decent scope, which is the UNI-T 4102C. It is honest for its price, because offers a pretty wide bandwidth, along with a 16 channel logic-analyzer.

http://www.uni-trend.com/UTD4102C.html

 

There are several good brands such as Rigol or Atten. I almost thrown a dice for choosing between the UNI-T and the Atten.

http://www.attenelectronics.com/

I definitely chosen the UNI-T (despite was older than Atten) for these reasons:

- 1MB of memory cache;

- 2GSa/s

The Atten had a wider screen, but I think it's a minor features than the above.

Cheers


Biggest fault of Netduino? It runs by electricity.

#39 pjnowak

pjnowak

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 03 February 2013 - 06:07 PM

I am having trouble getting my SPI to work with the Netduino Plus 2.  I am using Stefan's example, and it worked with the NP but not with the NP 2.  I did upgrade to [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]4.2.2.1.[/color]



#40 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 February 2013 - 08:19 PM

I am having trouble getting my SPI to work with the Netduino Plus 2.  I am using Stefan's example, and it worked with the NP but not with the NP 2.  I did upgrade to [color=rgb(40,40,40);][font="helvetica, arial, sans-serif;"]4.2.2.1.[/color][/font]

What device are you connecting to? What speed?

Chris




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.