Netduino home hardware projects downloads community

Jump to content


Photo

Application Development on the STM8S


  • Please log in to reply
26 replies to this topic

#1 Nevyn

Nevyn

    Advanced Member

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

Posted 31 August 2012 - 11:13 AM

For a few months now I have been writing a series of blog posts on using the STM8S chip with the aim that I may actually get to the point where I can show how to develop a module using the chip. The series has been titled The Way of the Register since I had a few problems with the STD Peripheral Library produced by ST and moved on to direct register access on the chip. Each article in the series takes a distinct task and describes how to achieve the task using the STM8S. Where possible, full project and source code for the IAR environment is included. All of these examples use the STM8S103F3 chip. If you are using other chips (say the STM8S Discovery Board) then you will also want to have a look at the post on Converting The Way of The Register Examples in order to work out what you will need to do in order to convert these examples. You can find the series on The Way of the Register page. I have covered the following topics so far:

 

Converting STD Library Code to use Direct Register Access on the STM8S

Going from using the STD Peripheral Library on the ST processors can be a little bewildering. This article attempt to guide you through the process of converting you code from using the STD Peripheral library to using registers.

 

Simple GPIO

Toggle a single GPIO line to produce an approximate square wave signal.

 

Configuring the System Clock on the STM8S

 

Configure the system clock to use the internal HSI oscillator running at 16MHz. Generate a square wave signal using a GPIO line and show how the frequency of the square wave can be changed by manipulating the clock divider.

 

External Interrupts on the STM8S

Capturing user input through a switch using the STM8S.

 

Using the UART on the STM8S Microcontroller

Learn how to setup and use the serial port on the STM8S to generate debug information or control serial devices.

 

Generating a regular signal using Timers

Here we will learn how to use one of the timers on the STM8S to generate a square wave signal.

 

Generating a PWM signal on the STM8S

In this article we look at generating a PWM signal using channel 1 of Timer 2 on the STM8S.

 

Interrupts on the STM8S

An overview of how interrupts works on the STM8S

 

Single Pulse Generation and Timer 1 Counting Modes These two articles take a look at Timer 1 and show how to generate a single pulse of a known length and also suggest some modifications which can be made as a exercise to show the different counting modes available on this timer.

 

Single mode ADC Conversion

Setup the ADC to perform a single conversion and then use that value to control the properties of a PWM signal and hence control the brightness of the LED. I have also converted a number of the sample programs to us not only my own reference platform but also the Variable Labs Protomodule and the STM8S Discovery boards.

 

STM8S SPI Slave

This post sets up SPI on the STM8S using hardware chip select. The data exchange is restricted to single bytes.

 

STM8S SPI Slave (Part 2)

This post adds buffering to the SPI data exchanges and uses software controlled chip select to determine when data transfer should be started.

 

STM8S SPI Slave (Part 3) - Making a Netduino Go Module Building on the previous two SPI posts, this one implements a simple GoBus comms protocol allowing module developers to create simple modules using the STM8S.

 

Transmitting Data Using SPI Master Mode

Using the master mode of the SPI interface on the STM8S to control the brightness of 16 LEDs connected to the TLC5940 16-channel PWM controller IC.

 

Storing Data in EEPROM on the STM8S

Writing a small amount of data in the EEPROM area of the STM8S in order that the data can survive a device reset or loss of power.

 

Using the Auto-Wakeup Feature on the STM8S Discovery Board

Using the Auto-Wakeup feature after a predefined time period of up to 30s.

 

STM8S Independent Watchdog

Adding an independent watchdog to detect software failure/locks.

 

STM8S Beep Function

Using the Beep function to generate signals from 50Hz to 32KHz.

 

STM8S Window Watchdog

Detecting software failure using the Window Watchdog function.

 

STM8S as an I2C Bus Master

Reading the temperature on a TMP102

 

STM8S as an I2C Slave Device

Creating a simple I2C salve device

 

Hope that you find this useful,

Mark

 

Edit: Converted the headings into links to the original posts.

Edit: 8th Oct 2012 - Added details on four additional posts.

Edit: 19th Nov 2012 - Added details about two SPI posts.

Edit: 26th Nov 2012 - Add the Module post link and information.

Edit: 1st Dec 2013 - Added links to two new posts, SPI master data transmission and storing data in EEPROM.

Edit: 20th Jun 2014 - Added a link to the Auto-Wakeup article

Edit: 21 June 2014 - Added link to Watchdog post.

Edit 5 August 2016 - Added additional samples.


Edited by Nevyn, 05 August 2016 - 05:38 AM.

To be or not to be = 0xFF

 

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

Follow @nevynuk on Twitter


#2 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 31 August 2012 - 12:10 PM

Nice work, i have been following the posts as they come online with interest, keep up the good work :) Dunno if it would be worth while linking to each article as well as the index page on your post above, despite knowing the titles weren't links i wanted to click them anyway ;) Nak.

#3 Nevyn

Nevyn

    Advanced Member

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

Posted 31 August 2012 - 01:36 PM

Nice work, i have been following the posts as they come online with interest, keep up the good work :)

Dunno if it would be worth while linking to each article as well as the index page on your post above, despite knowing the titles weren't links i wanted to click them anyway ;)

Glad you are following the articles :)

I've converted the headers as suggested.


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


#4 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 31 August 2012 - 05:11 PM

Great work Mark. -Fabien.

#5 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 31 August 2012 - 07:49 PM

This is fantastic stuff!, now only to get time to try this, the converting article is very good, I feel we need articles like that to get things up and running. Would be great if someone had pros-cons about the various toolchain offerings also, as for me, I havent installed any yet, and are open for suggestions, but I'm not so sure if I want to pay a lot for it :) (Thinking about these 8k limits and stuff)

--
Asbjrn


#6 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 31 August 2012 - 08:17 PM

Mark I can't express how immensely helpful these articles have been for me, and to many of the other community members. Until reading your posts I had merely purchased my STM8S Discovery Kit, and a ProtoModule, and installed IAR. Beyond that, everything was out of reach for me and seemingly over complicated, especially when coming from Visual Studio environment. Thanks to your posts the world of STMicroelectronics and Netduino Go module development have been revealed to me (Though I doubt I will be releasing any commercial modules anytime soon due to my utter ignorance of the C language). You have provided me the tools and afforded me the knowledge to develop using the STM8S, and no longer just a spectator. And for that, I thank you.

Now, can we expect 5 more post next week? :)

Cheers,
Steve

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 31 August 2012 - 08:48 PM

Hi neslekkim,

This is fantastic stuff!, now only to get time to try this, the converting article is very good, I feel we need articles like that to get things up and running.
Would be great if someone had pros-cons about the various toolchain offerings also, as for me, I havent installed any yet, and are open for suggestions, but I'm not so sure if I want to pay a lot for it :) (Thinking about these 8k limits and stuff)

We recommend IAR Embedded Workbench for STM8S (free version has an 8KB limit) and Keil ARM-MDK for STM32 (free version has a 32KB limit). All of our samples will use those project formats.

Chris

#8 Nevyn

Nevyn

    Advanced Member

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

Posted 01 September 2012 - 07:00 AM

We recommend IAR Embedded Workbench for STM8S (free version has an 8KB limit) and Keil ARM-MDK for STM32 (free version has a 32KB limit). All of our samples will use those project formats.


I'll second Chris on the IAR front - I can't comment on ARM-MDK as I have not tried it. For what it's worth, I've tried IAR Kickstarter and ST Develop and I found IAR to be more friendly to the developer.

For the STM32 I did download and have briefly played with the Atolic environment (2.3.0 Lite) and that was OK - based on Eclipse I believe. They changed the rules when they moved from 2.3.0 to 3.0, 2.3.0 was feature restricted (i.e. only one breakpoint etc.) but not code restricted, 3.0 is unrestricted features but code is restricted to 32KBytes. In terms of capability it looked OK but I have only used it briefly.

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


#9 Nevyn

Nevyn

    Advanced Member

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

Posted 03 September 2012 - 08:14 PM

Just added a couple of new posts if you are interested:


Interrupts on the STM8S
An overview of how interrupts work on the STM8S including setting priorities for the various interrupts and how to tell the compiler that a method is an ISR and which vector it relates to.

Generating a Pulse Using STM8S Timers
This post examines two methods for generating a single pulse of a defined width using the STM8S.

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


#10 Nevyn

Nevyn

    Advanced Member

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

Posted 07 October 2012 - 07:26 PM

Some time last month I added a new post on ADC conversion and linked this to PWM output to control the brightness of an LED.

I've also become aware of a problem which prevented some of the examples from running on the STM8S Discovery board (credit where it's due, the answer came from a discussion between Fabien and Gutworks). So I've recently spent some time checking the examples and converting some of the programs to make them more compatible with both the Discovery board and the Variable Lab Protomodule. It's still a work in progress but the new sources and the compatibility list can be found in this post.

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


#11 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 07 October 2012 - 08:47 PM

Very nice Mark. Thank you for sharing this! Chris

#12 Nevyn

Nevyn

    Advanced Member

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

Posted 19 November 2012 - 12:35 PM

Added a couple of posts on SPI slave devices. The original post at the head of this thread has been updated with links. 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


#13 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 19 November 2012 - 12:51 PM

I see that you use the Netduino Plus here, I still have only the Go, so I wonder. Can I use the Go, set it up to talk to the STM8, and make the STM8 talk to an other SPI unit?, it's probably stupid&overkill, but I have these spi based 7segment leds which is discussed here: http://dangerousprot....php?f=2&t=4541 For some reason I cannot make SPI work on my Arduino Due, so I want to test it on another platform to see what works or not.

--
Asbjrn


#14 Nevyn

Nevyn

    Advanced Member

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

Posted 19 November 2012 - 01:06 PM

I see that you use the Netduino Plus here, I still have only the Go, so I wonder.
Can I use the Go, set it up to talk to the STM8, and make the STM8 talk to an other SPI unit?, it's probably stupid&overkill, but I have these spi based 7segment leds which is discussed here: http://dangerousprot....php?f=2&t=4541

For some reason I cannot make SPI work on my Arduino Due, so I want to test it on another platform to see what works or not.

Yes you can do that although you would probably have to bit bang the SPI data yourself as you only have one SPI port and that would be used to talk to the Go. The SPI apps I have presented bit bang serial data when outputting the debug data on Port D. You would just need to add a chip select. I'm assuming you would not be getting data back on the MISO line as these are 7-segment displays.

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


#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 November 2012 - 05:01 PM

Hi Nevyn, neslekkim:

Yes you can do that although you would probably have to bit bang the SPI data yourself as you only have one SPI port and that would be used to talk to the Go.


Just FYI: you can use the STM8S UART in SPI mode as well. Not quite as nice as the native SPI peripheral, but an awesome option.

Chris

#16 Nevyn

Nevyn

    Advanced Member

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

Posted 19 November 2012 - 05:30 PM

Just FYI: you can use the STM8S UART in SPI mode as well. Not quite as nice as the native SPI peripheral, but an awesome option.

I've noticed the fact that the 103's have the option of outputting the UART clock on one of the pins - just not had the time to try it. That has crossed my mind as an option for a slow SPI replacement.

Too much to do, to little time to do it....


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


#17 Lunddahl

Lunddahl

    Advanced Member

  • Members
  • PipPipPip
  • 152 posts
  • LocationEurope, Denmark

Posted 19 November 2012 - 07:02 PM

Added a couple of posts on SPI slave devices. The original post at the head of this thread has been updated with links.


Very nice Mark, thanks. I'm looking forward to the next posts in the series, why else would you select 17 as the buffer length...

:-)

A final note, i wider site theme will make the code look much more readable, those warped comments is poison for the eyes.

- Ulrik

#18 Nevyn

Nevyn

    Advanced Member

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

Posted 26 November 2012 - 09:14 PM

Very nice Mark, thanks. I'm looking forward to the next posts in the series, why else would you select 17 as the buffer length...

New post available....

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


#19 sgraves

sgraves

    Member

  • Members
  • PipPip
  • 16 posts

Posted 28 November 2013 - 05:11 AM

Definitely a big thanks for this series on STM8. They've proven to be an invaluable resource to me.



#20 Nevyn

Nevyn

    Advanced Member

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

Posted 28 November 2013 - 07:20 AM

Definitely a big thanks for this series on STM8. They've proven to be an invaluable resource to me.

Thank you, I'm glad that these posts are still proving useful.

 

I'm still using the STM8S on other projects as it's a great low cost chip.

 

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





1 user(s) are reading this topic

0 members, 1 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.