XMOS startkit Step 1

So after spending all day yelling at my XMOS startkit I finally got a basic hello world flashing led code to work. This code flash’s one of the two leds closest to the ram.

#include <xs1.h>
#include <timer.h>

port p = XS1_PORT_1D;
int main() {
 while (1) {
     p <: 0;
delay_milliseconds(200);
p <: 1;
delay_milliseconds(200);
}
}

So how does all this work?

First up we need to reference the required header files. The most important one is xs1.h contains the core functions for working with XMOS Chips. We add this by adding the line

#include <xs1.h>

This contains the port definitions so that our programs will know what port p = XS1_PORT_1D means.

The second one required for the program to work is

#include <timer.h>

This allows us to use the timing function of the chip (I may be mistaken here in that it could actually be a core “C” header!) and allows the code to understand what delay_milliseconds(200); means.

After we have those two lines we need to define which pin our LED is connected to. According to the Startkits hardware manual the two of the leds are labelled D1 & D2 and are accessed through ports 1A and 1D (see page 10/17) and to access them we need to add

port p = XS1_PORT_1D

By changing port p = XS1_PORT_1D; to port p = XS1_PORT_1A; you can change between one of the two leds that are located next to the 256KB SPI flash chip. According to the schematic diagram in the hand book, these leds are connected between the chips pin and ground making them active low. To turn them on the chip needs to supply power to the led and this is done with the following.

p <: 1;

If you noticed the code, I put this line near the end, this is because on each cycle the following

 while (1) {
     p <: 0;

Checks to see if the if the variable “p” high (1), if it is, the pin is set low (0) by the following line. then after a delay, if the variable “p” is high the it will be set low and XS1_PORT_1D will be switched off.

If I understand myself, then all this will make sense and you (the reader) should be able to follow this.

Well I have had enough programming for today so time to pack up.

Advertisements