Ok, so I am trying to toggle the Match pin 1 for the MCB2140 with the Timer0. Basically, like a PWM except it is either on or off for the cycle time, never in between.
Unfortunately, the pin seems to be at an undefined voltage level of .5 V except when I am using the JTAG debugger and it stays at 3.3 V all the time, even though it is suppose to initialize to logic 0.
Could anyone offer insight?
#include <LPC21xx.H> #include <stdio.h> #define ARRAY_SIZE 5 //#define CYCLE_LENGTH 0xFFFFFFFF #define CYCLE_LENGTH 0x00000FFF unsigned char BUFF0[]={'U', 'Y', 'Z', 'A', 'B'}; int bit_count=0; int byte_count=0; void T0isr(void) __irq; void init_timer1(void) { PINSEL0 |= 0x00000800; //Match1 as output T0TCR = 0; //TIMER1 set as timer to PCLK T0PR = 4; //Set Prescale Register (divider) to 4 T0TCR = 2; //Reset counter and prescaler T0MCR = 3; //On match reset the counter and generate an interrupt T0MR0 = CYCLE_LENGTH; //Set the cycle time T0MR1 = 0; // Set duty cycle to zero T0EMR = 0x042; //On match clear MAT1 T0TCR = 1; //TIMER1 ENABLE } void init_bus(void) { //PINSEL0 |= ~0x0000003; //assures that P0.0 is set to GPIO Port 0.0 } void init_VIC(void) { VICVectAddr4 = (unsigned)T0isr; //Set the timer ISR vector address VICVectCntl4 = 0x00000024; //Set channel VICIntEnable |= 0x00000010; //Enable the TIMER0 interrupt } void init_LED(void) { IO1DIR = 0x00FF0000; IO1PIN = 0x00550000; } int main(void) { init_LED(); init_timer1(); init_bus(); init_VIC(); while(1); { //... } } void T0isr (void) __irq { T0EMR |= 0x00000002; //Set MAT1 high for begining of the cycle //debug ////////////////////////////////// IO1PIN = ((IO1PIN+1)& 0x00FF0000); ////////////////////////////////// if(bit_count < 8) { if(BUFF0[byte_count] & 0x01) //set match 1 to cycle time (setting biit high if { T0MR1 = CYCLE_LENGTH; //bit is supposed to be a '1' } else { T0MR1 = 0; //else set match 1 to 0 to force output to a zero. } bit_count++; BUFF0[byte_count] = BUFF0[byte_count] >> 1; //shift byte over by one bit for next transfer } else if((bit_count == 8) && (byte_count < ARRAY_SIZE)) //a new byte! { bit_count=0; //reset bit count for new byte byte_count++; //establish new byte number of buffer if(BUFF0[byte_count] & 0x01) //set match 1 to cycle time (setting biit high if bit is supposed to be a '1' { T0MR1 = CYCLE_LENGTH; } else { T0MR1 = 0; //else set match 1 to 0 to force output to a zero. } bit_count++; BUFF0[byte_count] = BUFF0[byte_count] >> 1; //shift byte over by one bit for next transfer } else //ERROR or DONE { //unhandled } T0IR = 1; //Clear match 0 interrupt VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt }