Vous êtes sur la page 1sur 3

C Programming for Embedded Microcontrollers –

Important Notes

Version 1.0
3 February 2009
by W.A. Smith

Table of Contents
1. Page 184 - Problem with the LED_two program when running from SRAM.................................2

2. Page 203 to 204 - Problem with the serial_tx program running from SRAM.................................3

1
1. Page 184 - Problem with the LED_two program when
running from SRAM
9.2 Writing to More than One LED

The LED_two program needs a delay routine inserted at the beginning of main(). There is some
clash between the SAM-BA program that is running and the LED_two program that starts running
resulting in the LED_two program not working.

Note that this will only occur when running this program from SRAM. If you use the Flash
template to build the program for Flash memory and then load and run it from Flash memory, you
will not encounter any problems.

Simply call the Delay() function to correct the problem as follows:

#include "at91sam7s.h"

void Delay(void);

int main(void)
{
Delay(); // <--- Call Delay() here to solve problem
PIO_PER = 0x00000003;
PIO_OER = 0x00000003;

while (1) {
PIO_CODR = 0x00000001;
PIO_SODR = 0x00000002;
Delay();
PIO_SODR = 0x00000001;
PIO_CODR = 0x00000002;
Delay();
}
}

void Delay(void)
{
int del = 5000000;

while (del--);
}

2
2. Page 203 to 204 - Problem with the serial_tx program
running from SRAM
10.2 Programming the Serial Port

When the serial_tx program is run from SRAM, the first few letters that are sent to
HyperTerminal are corrupted. This problem will not occur when using the Flash template files and
loading the program to Flash memory. The problem is solved the same way as the previous one by
adding a delay routine at the start of main() as follows:

#include "at91sam7s.h"

#define DBGU_115200 26

void DBGUInit(unsigned int baud);


void DBGUTxMsg(char* msg);
void Delay(void);

int main(void)
{
Delay(); // <--- Add delay routine
DBGUInit(DBGU_115200);

DBGUTxMsg("Hello from DBGU port!\r\n");

while (1) {
}
}

void DBGUInit(unsigned int baud)


{
PIO_ASR = 0x00000600;
PIO_PDR = 0x00000600;

DBGU_BRGR = baud;
DBGU_MR = 0x00000800;
DBGU_CR = 0x00000050;
}

void DBGUTxMsg(char* msg)


{
int ch_num = 0;

while (msg[ch_num] != 0) {
while (!(DBGU_SR & 0x00000002));
DBGU_THR = (unsigned int)msg[ch_num];
ch_num++;
}
}

void Delay(void)
{
int del = 5000000;

while (del--);
}

Vous aimerez peut-être aussi