Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Robert Bowen
04/24/13 14:48
Modified:
  04/24/13 15:00

Read: 2185 times
St. Peters
USA


 
#189698 - UART C vs ASM - Interrupts
I'm lost....I am trying to rewrite some code from my NXP '51 to SiLabs F580 micro using C and I am stuck on a simple task. I thought I would share my problems in hope that someone would shed some light on my mishaps.

psuedo hardware:

[PC-RS-232] <------> [UART micro] (PC sends cmds down to micro)

CMD1() = Write to DAC. User sends command to ramp from 0V to 10V.

CMD2() = Set variable bit = 1. User sends CMD2() while CMD1() is running to STOP/HOLD the ramp function.

PROBLEM: If I send CMD1() first, then send CMD(2) it does not run until AFTER CMD(1) is COMPLETE. (Ooops! too late! Crash and burn!)

In my ASM code, this worked fine. I would issue CMD1() and in the middle of the RAMP I would send CMD2() which would set a bit that CMD1() would read and then HOLD. (Basically, after each count I sent to the DAC it would examine if the bit was set.) If it was SET it would hold HOLD.

JB PROGRAM_HOLD,$


in ASM, I configured UART for Interupt driven, I had a command lookup table and if in the middle on any cmd() a new cmd was received, the ISR serviced it then went back to what it was doing.

Now, if I send CMD1() and then send CMD2() in the middle of CMD1() execution, it will NOT interrupt it until AFTER CMD1() is complete.

I am confident that my ISR is working correctly. To test I do this... As you will see, I have my ISR set the value of RampHold to 99 and then printf just to see if the value has changed, And indeed it has. So the ISR runs, but NOT until AFTER CMD1() is complete.

You got me!???

void main(void)
{
while(1)
{
cmd = getkey()
switch (cmd)
{
case 1: CMD1();
break;
case 2: CMD2();
break;
}
}

void CMD1(void)
{
for loop to ramp ....
}

void CMD1(void)
{
RampHold = 1;
}


INTERRUPT(UART0_ISR, INTERRUPT_UART0)
{

if (RI0 == 1)
{
RI0 = 0; // Clear interrupt flag
Byte = SBUF0; // Read a character from UART
RampHold = 99;
}
}




This has got to be something silly I am over-looking here!

List of 4 messages in thread
TopicAuthorDate
UART C vs ASM - Interrupts      Robert Bowen      04/24/13 14:48      
   after each count I sent to the DAC it would it would examine      Jan Waclawek      04/24/13 22:36      
   How I would think of it      Oliver Sedlacek      04/25/13 02:48      
      UART C vs ASM - Interrupts      Robert Bowen      04/25/13 05:26      

Back to Subject List