RNet Stack for 8bit MC9S08QE128 Microcontroller and MC13201 Transceiver

I admit: I have used ARM Cortex cores a lot in the recent months. Yes, I think with the ‘ARM domination of the world’ over time the ARM core will blast away probably all other cores, except for niche players? Still, there are reasons to use non-ARM cores, and even if it is just that I have a board at hand :-).

DEMOQE with MC9S08QE128 and MC13201 Transceiver Card

DEMOQE with MC9S08QE128 and MC13201 Transceiver Card

Flexis?

So I do have two Freeescale DEMOQE boards which I have not touched much in the last two years. Freescale introduced these boards with the ‘Flexis’ cores: a nice concept to ease the migration from 8bit (Freescale S08 core) to the 32bit world (Freescale ColdFire core). The DEMOQE (and DEMOJM) boards came with red 32bit and green 8 bit processor modules. The processors in each family are pin compatible, so it is very easy to change from 8bit to 32bit and back. I loved that concept, as with the same peripherals, it was possible to explore the power of a 32bit core. With the move of Freescale into the ARM domain, things got calm on this domain, and I feel that this great concept has been abandoned by Freescale? Why not having the same concept say from 8bit S08 to ARM, or 32bit ColdFire to 32bit ARM? That would be awesome! Yes, that Big Endian to Little Endian would be a challenge. But I would *love* to have the S08 peripherals on an ARM core! The S08 (and S12) peripherals are so much better what Freescale has on the ARM Kinetis parts, and I’m not alone with this opinion. I started to truly value the S08 peripherals once I move to the Kinetis parts: it is like day and night from the functionality, stability and easy-to-use aspects. Yup, I stop whining now, as I know the future is ARM and 32bit, but I hope that the goodies of the 8bit world will migrate to the ARM world.

RNet on 8bit?

I’m a believer that software and stacks are only good if they run on multiple platforms and cores. I have developed the RNet wireless stack and use it mainly on ARM Cortex M0+ (see this post). Having a stack running with different transceivers, compilers and microcontroller for sure helps to improve it. So for this article I run the RNet stack with the Freescale MC13201 transceiver card. In case you want to run the stack on a different microcontroller, the porting details in this post should help you.

The example project discussed in this article is available on GitHub.

DEMOQE Connections to Transceiver

The DEMOQE board has a connector on the downside of the board making it easy to extend it to a custom board. I have created a breakout board for the MC13201, so I have wired the two boards together:

MC13201 Transceiver Connections

MC13201 Transceiver Connections

The pin connections are as below:

=================================================================
THIS FILE WAS GENERATED BY "Processor Expert version 10.3 for Freescale Microcontrollers".
Project "ProcessorExpert", 2013-12-25, 10:51, # CodeGen: 26
DO NOT MODIFY IT.
=================================================================

=================================================================
 SIGNAL LIST
-----------------------------------------------------------------
SIGNAL-NAME [DIR]        => PIN-NAME [PIN-NUMBER]
-----------------------------------------------------------------
LED0 [Output]            => PTC0_TPM3CH0 [34]
LED2 [Output]            => PTC1_TPM3CH1 [33]
LED3 [Output]            => PTC2_TPM3CH2 [25]
LED4 [Output]            => PTC3_TPM3CH3 [24]
LED5 [Output]            => PTC4_TPM3CH4_RSTO [78]
LED6 [Output]            => PTC5_TPM3CH5_ACMP2O [77]
LED7 [Output]            => PTE6 [20]
LED8 [Output]            => PTE7_TPM3CLK [7]
Radio_ATTN [Output]      => PTG1 [73]
Radio_CE [Output]        => PTD1_KBI2P1_MOSI2 [1]
Radio_CLK [Output]       => PTB2_KBI1P6_SPSCK1_ADP6 [40]
Radio_IRQ [Input]        => PTD0_KBI2P0_SPSCK2 [2]
Radio_MISO [Input]       => PTB4_TPM2CH1_MISO1 [23]
Radio_MOSI [Output]      => PTB3_KBI1P7_MOSI1_ADP7 [39]
Radio_RESET [Output]     => PTH0 [19]
Radio_RTXEN [Output]     => PTH1 [18]
RxD [Input]              => PTB0_KBI1P4_RxD1_ADP4 [42]
TxD [Output]             => PTB1_KBI1P5_TxD1_ADP5 [41]
=================================================================

=================================================================
 PIN LIST
-----------------------------------------------------------------
PIN-NAME [PIN-NUM]       => SIGNAL-NAME [DIRECTION]
-----------------------------------------------------------------
PTB0_KBI1P4_RxD1_ADP4 [42] => RxD [Input]
PTB1_KBI1P5_TxD1_ADP5 [41] => TxD [Output]
PTB2_KBI1P6_SPSCK1_ADP6 [40] => Radio_CLK [Output]
PTB3_KBI1P7_MOSI1_ADP7 [39] => Radio_MOSI [Output]
PTB4_TPM2CH1_MISO1 [23]  => Radio_MISO [Input]
PTC0_TPM3CH0 [34]        => LED0 [Output]
PTC1_TPM3CH1 [33]        => LED2 [Output]
PTC2_TPM3CH2 [25]        => LED3 [Output]
PTC3_TPM3CH3 [24]        => LED4 [Output]
PTC4_TPM3CH4_RSTO [78]   => LED5 [Output]
PTC5_TPM3CH5_ACMP2O [77] => LED6 [Output]
PTD0_KBI2P0_SPSCK2 [2]   => Radio_IRQ [Input]
PTD1_KBI2P1_MOSI2 [1]    => Radio_CE [Output]
PTE6 [20]                => LED7 [Output]
PTE7_TPM3CLK [7]         => LED8 [Output]
PTG1 [73]                => Radio_ATTN [Output]
PTH0 [19]                => Radio_RESET [Output]
PTH1 [18]                => Radio_RTXEN [Output]
=================================================================

For the transceiver connection, the following signals are required:

  1. SPI connection with CE, MISO and MOSI
  2. Radio ATTN, RXTXEN and IRQ

SPI Settings

The SPI communication is implemented with the SynchroMaster component:

SPI SynchroMaster

SPI SynchroMaster

The SPI needs isconfigured as below:

  • No interrupts (the low-level driver for the MC13201 is not using interrupts (yet)).
  • MISO, MOSI and Clock pin. No slave select pin, as handled in the tranceiver driver.
  • Clock edge: falling (data on the SPI is shifted on the falling edge)
  • Most Significant Bit (MSB) first
  • Clock idle polarity: Low
  • SPI clock settings: list of values (details below)
SPI Settings

SPI Settings

SPI Clock Settings

The SPI bus can be used by other components too (although I admit I have used the MC13201 as the only device on the bus). Anyway, to support multiple bus participants, the bus needs to be set up with a ‘list of values’. For this I click on the ‘…’ for the clock settings (you need first to click into the field!):

Shift Clock Rate

Shift Clock Rate

The MC13201 can run up to 8 MHz SPI clock. So I configure it to use a list of values, and use a value <= 8 MHz for the Mode (index) zero:

List of SPI Clock Values

List of SPI Clock Values

I will use that index zero later in the transceiver settings.

Transceiver Settings

The pins for the transceiver are configured inside the SMAC component:

Transceiver Signals

Transceiver Signals

Transceiver Properties

In the transceiver settings I configure the transceiver type, point to the SPI ‘list of values’ index zero (see SPI settings above):

Transceiver Settings

Transceiver Settings

IRQ Settings

The interrupt pin is configured with pull-up and to generate an interrupt on falling edge:

Interrupt Configuration

Interrupt Configuration

What is left over is the probably most complicated part: the configuration of the IRQ (interrupt) pin of the transceiver. Processor Expert usually makes things easy, but in the case of interrupt pin handling important functionality is missing in the interrupt API: there is no way to acknowledge the interrupt pin from the driver :-(. Instead, I need to define a macro to acknowledge the interrupt so I can use it in the driver.

First I need to know how to clear the flag. This I can get from the Processor Expert code generated for the IRQ pin I have assigned:

Clear the Interrupt flag

Clear the Interrupt flag

This code I can use in my settings. I click the ‘…’ for the string list:

IRQ Macro Settings

IRQ Macro Settings

Then I assign the code to the IRQACK() macro:

IRQACK Macro

IRQACK Macro

CPU Settings

As the stack transceiver can use low power wait mode, I enable that method in the CPU component:

SetWaitMode

SetWaitMode

RNet Integration

The RNet integration is very similar for the ARM Cortex (see this post and this post). For the MC13201 transceiver I need to link the interrupt event to the event handler in the Radio.c module. For this I add an include to Events.c:

/*
** ===================================================================
**&nbsp;&nbsp;&nbsp;&nbsp; Event&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp; SMAC1_OnInterrupt (module Events)
**
**&nbsp;&nbsp;&nbsp;&nbsp; Component&nbsp;&nbsp; :&nbsp; TRSVR1 [MC13192]
**&nbsp;&nbsp;&nbsp;&nbsp; Description :
**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Event raised in case of transceiver interrupt.
**&nbsp;&nbsp;&nbsp;&nbsp; Parameters&nbsp; : None
**&nbsp;&nbsp;&nbsp;&nbsp; Returns&nbsp;&nbsp;&nbsp;&nbsp; : Nothing
** ===================================================================
*/
void SMAC1_OnInterrupt(void)
{
  RADIO_OnInterrupt();
}

Not to forget to include the header file at the top of Events.c:

#include "Cpu.h"
#include "Events.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
#include "RadioSMAC.h"

That’s it 🙂

Shell Interface

The demo features a simple console/shell interface:

RNet with DEMOQE

RNet with DEMOQE

Trouble Shooting

What follows is more about dealing with known issues in Processor Expert and CodeWarrior for 10.5 😦

Processor Expert, S08 and RTOS in MCU10.5

Processor Expert fails to add the correct RTOS initialization code for S08 targets. To fix this, add the following code to main():

void main(void)
{
/* Write your local variable definition here */
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif

Banked Memory Model for S08 in MCU10.5

It looks like debugging for banked memory model is broken in MCU10.5 :-(. I thought I saw a patch for this somewhere on the Freescale web site, but I have found it. So my project on GitHub is using the small memory model. I was able to use banked memory model with MCU10.3.

Do NOT load projects with different Eclipse versions!

The other thing is: do NOT try to load the same project with different Eclipse versions! It is ok to load say a 10.4 project into 10.5 (upwards compatibility). But once you loaded it in a higher version, bad things can happen if you load it with an earlier version (e.g. 10.4), and then again in a newer version (10.5):

CW ProjectsView Project Loading Verification Error

CW ProjectsView Project Loading Verification Error

This problem is reported in the Freescale Forum too.

❗ This is a nasty thing, but common to many tool chains, not only Eclipse (I had similar things with IAR too). As a general advise: never load ‘never’ projects with ‘older’ IDE versions. It might work sometimes, but if things can go bad, they will.

Summary

Although things are moving to 32bit ARM cores, using software and stacks with 8bit cores still can make sense, especially if they are at hand ;-). Apart of that, using the stack with the 8bit HCS08 allowed me to fix some minor issues, and if it is only to fix possible compiler warnings for my source code. The full project and sources are available on GitHub.

Happy 8biting 🙂

6 thoughts on “RNet Stack for 8bit MC9S08QE128 Microcontroller and MC13201 Transceiver

  1. Thank you for the fast response!

    You are the best! I really need this, I almost feel guilty knowing you do this in your holidays…

    If I have a problem, or better yet, if I can add my grain of sand, I’ll let you know by this same route.

    I owe you a big one.

    Thanks again!

    Like

  2. I can’t say that I understand this mass movement to ARM. I have previously designed products using a variety of processors – from Z80’s back in the day, through Rabbits, 8051’s, Zilog Z8‘s and ARM7. Currently I have a product using a MC9S08QE, another in the advanced stages using a Coldfire V2, and am in the early stages of a designing a product with a Coldfire V4. I don’t see the core as being that important. You mentioned the peripherals – I totally agree, having consistent and reliable peripherals are more important, as well as a trustworthy tool chain. In my experience anyway.

    It’s funny these days, I get graduates that go all dreamy eyed when ARM is mentioned, but they can’t reason why. It’s almost like some kind of religion – very curious 🙂

    Like

    • Yes, it is some kind of religion, and this religion starts with the top management. I friend of mine put it that way: “If we propose management a non-ARM micrcontroller to be used, we receive a lot of questions, need to justify it to the very detail, and even if the data is clear, we get constantly challenged and questioned about why we have choosen that solution”. And at the time of the smallest problem, they say that this probably would not have happened if we would have choosen an ARM core. So they got constantly challenged because they somehow get the impression that ARM is the Holy Grail. On the other end, he said, if they propose an ARM microcontroller, he said that “no questions asked”. I see the same thing in different places, multiple times. There are good reasons for using an ARM core, but there are good reasons to choose a non-ARM core too. It is just about to choose what fits best to solve a problem. I think the biggest advantage of using ARM is that part of trustworthy tool chain: because of that many vendors of ARM, there are choices, while for a non-ARM core the selection of compiler/tool chain could be very limited. On the other end I see a big danger for the ARM world: because everyone thinks that there is an eco-system large enough, vendors are not investing any more in software and tools. You get pretty good tools for free for ARM development (see my DIY series), but the same time it seems to me that there is not enough money left on the table for commercial (good quality) tools: even if there are a lot of ARM core users, there are many, many tool providers, not leaving enough business opportunity on the table for a good business? On the other end, for the customer at least in the short term there is a benefit of lower prices. But I think in the longer run quality of software and tools will suffer, because nobody is willing to invest?

      Like

      • Thanks for your management story and very good points on toolchain development Erich. I’m happy to pay a few hundred dollars or so for a tool chain but am glad that there is an alternative to the old days of having to pay many thousands of dollars.

        I started work for a company on a project that was late and over budget several years ago. They had recently decided to standardise on ARM for all future reasonably complex products. So, they purchased an RTOS and Kiel compiler for $20K, and designed a core module using an Atmel ARM7 for new products. It turned out that the core module blew the power budget, so they redesigned a simpler one using a NXP LPC213x. It didn’t have a huge amount to do and so was only clocked at 8MHz. It turns out that the digital I/O peripheral was slow, so they had to increase the clock speed (consuming more current). They then found they didn’t have enough resolution on the ADC so had to add an external 12 bit ADC. They could have chosen any of dozens of non-ARM processors, such as a CFV1, a higher clocked 8 bit QE, or even a MCF5213 which had been around for donkies years at the time, and at the original clock speed and about the same or less current, and ended up with a better solution. In this example, it was the periphals that were important, not the core, using ARM didn’t save them 🙂

        Also, the $20K they spent gave them one delevopment seat, which was node locked to our software engineer. To do hardware testing, I had to build myself a GCC based ARM toolchain anyway. If they’d had used a Freescal part and CodeWarrior, the size of the code was below the Special Edition limit (and similar with other vendors), and we could have all had the same toolchain! That’s one of the great benefits of low priced or free tools.

        Like

        • Yes, only after using more and more ARM cores (including ones from Freescale) I realize how amazingly excellent the peripherals on the S08 and CFV1 are. It starts with the timers which are much easier and better to use, including PWM and things like UART. A good thing about ARM is the presence of a more broad (and free) tool chain ecosystem, and that (as you did) I can build up my own ARM GCC based toolchain with Eclipse.

          Like

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.