[an error occurred while processing this directive]
|
Использую ARM LPC2138. Вот инициализация:
//XTAL frequency in Hz
#define XTALFREQ 14745600
#define BAUDRATE 9600
extern int fillbuf;
int bufpos = 0;
#define FRAME_SIZE 160
extern short in_short_buf[FRAME_SIZE];
int GetProcessorClockFreq(void)
{
if((PLLCON & 0x3) == 0x3)
(PLLC & PLLE = 1), òî ìíîæèòåëü = MSEL + 1
return (((PLLCFG & 0x1F) + 1) * XTALFREQ );
return XTALFREQ;
}
int GetPeripheralClockFreq(void)
{
unsigned char c;
do { // Äëÿ êðåìíèÿ ðåâèçèè À, ýððàòà VPBDIV.1 îò 2005 May 2
c = VPBDIV & 0x03;
} while((VPBDIV & 0x03) != c);
switch (c) {
case 1:
c = 1;
break;
case 2:
c = 2;
break;
default:
c = 4;
}
return GetProcessorClockFreq() / c;
}
void uart0ISR(void)
{
unsigned char iid;
// perform proper ISR entry so thumb-interwork works properly
// ISR_ENTRY();
// loop until not more interrupt sources
while (((iid = U0IIR) & UIIR_NO_INT) == 0)
{
// identify & process the highest priority interrupt
switch (iid & UIIR_ID_MASK)
{
case UIIR_RLS_INT: // Receive Line Status
U0LSR; // read LSR to clear
break;
case UIIR_CTI_INT: // Character Timeout Indicator
case UIIR_RDA_INT: // Receive Data Available
do
{
in_short_buf[bufpos] = U0RBR;
if (bufpos +1 >= FRAME_SIZE)
fillbuf = 1;
bufpos = (bufpos +1) % FRAME_SIZE;
}
while (U0LSR & ULSR_RDR);
break;
case UIIR_THRE_INT: break; // Transmit Holding Register Empty
default: // Unknown
U0LSR;
U0RBR;
break;
}
}
VICVectAddr = 0x00000000; // clear this interrupt from the VIC
// ISR_EXIT(); // recover registers and return
}
static void DefDummyInterrupt()
{
}
void init_serial (void) { //Initialize Serial Interface
// Ðàçðåøàþ íîæêè
PINSEL0 = (PINSEL0 & 0xFFFFFFF0) | 0x00000005;
// Î÷èùàþ ðåãèñòðû
U0IER = 0x00;
U0IIR;
U0RBR;
U0LSR;
U0LCR = 1 << 7; // select divisor latches
U0DLL = (GetPeripheralClockFreq()/(BAUDRATE*16)) & 0x00ff;
U0DLM = ((GetPeripheralClockFreq()/(BAUDRATE*16)) >> 8) & 0x00ff;
U0LCR = 0x03; //8-bit, 1 stop bit,
U0FCR = 0x07; // Ðàçðåøàþ è ñáðàñûâàþ FIFO, ïðåðûâàíèå ïî ïåðâîìó ïîñòóïèâøåìó áàéòó
// Ðàçðåøàþ âûçûâàòü ïðåðûâàíèÿ
U0IER = 1; // Òîëüêî ïî ïðèåìó
VICIntEnClr = 0xFFFFFFFF; // clear all interrupts
VICDefVectAddr = (unsigned int)&DefDummyInterrupt;
/*
VICIntSelect &= ~(1<<6); //&= ~VIC_BIT(VIC_UART0); // UART0 selected as IRQ
VICIntEnable = 1<<6; //VIC_BIT(VIC_UART0); // UART0 interrupt enabled
VICVectCntl0 = (1<<5)&6; // VIC_ENABLE | VIC_UART0;
VICVectAddr0 = (uint32_t)uart0ISR; // address of the ISR
*/
// initialize the interrupt vector
VICIntSelect &= ~VIC_BIT(VIC_UART0); // UART0 selected as IRQ
VICIntEnable = VIC_BIT(VIC_UART0); // UART0 interrupt enabled
VICVectCntl0 = VIC_ENABLE | VIC_UART0;
VICVectAddr0 = (uint32_t)uart0ISR; // address of the ISR
}
int putchar (int ch){
U0THR = (uint8_t)ch;
return 1;
}
когда вызываю просто putchar(48), передается какая-то фигня. Для одной программы-приемника это символ з , для другой - символ p. Эти значения постоянны.
В чем могут быть причины?
Спасибо.
E-mail: info@telesys.ru