Forum Discussion
Altera_Forum
Honored Contributor
16 years ago --- Quote Start --- Please grit, ask your questions in only one thread at a time. Either put all your questions in one thread, or create a new thread for each question, but do not post them in multiple places. It makes it very difficult to follow up. What you are facing is probably a cache problem. The first time the CPU reads the switches value, it is put in its data cache. Then the other times the CPU will read the cached value instead of the one from the switches. One way to get around this is to uso the IORD/WR macros: (not compiled/tested, but the basic idea is there)
#include <io.h>
# define SWITCHES 0x0001800# define LEDS 0x0001810
void main()
{
while (1)
IOWR(LEDS,0,IORD(SWITCHES,0));
}
Or even better, to use the dedicated PIO macros: #include "altera_avalon_pio_regs.h"
# define SWITCHES 0x0001800# define LEDS 0x0001810
void main()
{
while (1)
IOWR_ALTERA_AVALON_PIO_DATA(LEDS,IORD_ALTERA_AVALON_PIO_DATA(SWITCHES));
}
Also check that the addresses that you put in the defines match the ones in your SOPC system. You should use the *_BASE constants that are automatically generated for you in system.h, it will same you some time and trouble. --- Quote End --- Hi, Daixiwen, sorry about the thread posting...I will put all my questions in one post next time... Your code works on my board! and the LEDs are now reacting accordingly. Thanks a million!