Пишу программу где необходимо наладить usart на плате.
Непосредственно usart запущен,т.е по Rx приходят данные (перемкнул ножки Rx и Tx,сам себе шлю 0xFF или 0xСС проверял в отладчике МТ-линк,так же проверял по факту зажигания лампочек в случае AT91C_BASE_US1->US_RHR==0xFF) Но плата должна получать целеуказания извне,а значит нужно прерывание по приему,вот оно у меня и не работает. По идеи в случае отправки 0xFF ,а она как видно происходит должно возникнуть прерывание -в коде обработчика код зажигания лампочки,т.е результат должен быть виден, но ничего не происходит. Пробовал прерывания по ENDRX и заполнению буфера(величина 1).(Работу программы с прерывание смотрю не по отладчику,т.к как я понял в прерываниях он не работает)
Ниже код одного из моих вариантов

CODE
#include "include/AT91SAM7X256.h"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\aic\aic.h"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\aic\aic.c"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\usart\usart.c"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\usart\usart.h"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\pmc\pmc.c"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\pmc\pmc.h"
//-------------------------------------------------------------
//bits
#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define BIT4 0x00000010
#define BIT5 0x00000020
#define BIT6 0x00000040
#define BIT7 0x00000080
#define BIT8 0x00000100
#define BIT9 0x00000200
#define BIT10 0x00000400
#define BIT11 0x00000800
#define BIT12 0x00001000
#define BIT13 0x00002000
#define BIT14 0x00004000
#define BIT15 0x00008000
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define BIT23 0x00800000
#define BIT24 0x01000000
#define BIT25 0x02000000
#define BIT26 0x04000000
#define BIT27 0x08000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000
/// Frequency of the board main oscillator.
#define BOARD_MAINOSC 16000000
/// Master clock frequency (when using board_lowlevel.c).
#define BOARD_MCK 48000000
#define LED0 BIT25
#define LED1 BIT22
#define LED2 BIT24
#define LED3 BIT23
#define USB_ON BIT7
/// Maximum Bytes Per Second (BPS) rate that will be forced using the CTS pin.
#define MAX_BPS 500
/// Size of the receive buffer used by the PDC, in bytes.
#define BUFFER_SIZE 1
/// Number of bytes received between two timer ticks.
volatile unsigned int bytesReceived = 0;
/// Receive buffer.
unsigned char pBuffer[BUFFER_SIZE];
/// String buffer.
char pString[24];
//-------------------------------------------------------------
void InitFrec(void)
{
// Set Flash Waite sate - Flash Memory Controler
// if MCK = 47923200 I have 50 Cycle for 1 usecond
AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN)&(48 <<16)) | AT91C_MC_FWS_1FWS;
// Watchdog Disable
AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
// 1 Enabling the Main Oscillator:
// SCK = 1/32768 = 30.51 uSecond
// Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
AT91C_BASE_PMC->PMC_MOR =
(( AT91C_CKGR_OSCOUNT & (0x06 <<8) | AT91C_CKGR_MOSCEN ));
// Wait the startup time
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
// 2 Checking the Main Oscillator Frequency (Optional)
// 3 Setting PLL and divider:
// - div by 5 Fin = 3,2 = (16,000 / 5)
// - Mul 29+1: Fout = 96,0 = (3,2 * 30)
// for 96 MHz the erroe is 0.0%
// Field out NOT USED = 0
// PLLCOUNT pll startup time estimate at : 0.844 ms
// PLLCOUNT 28 = 0.000844 /(1/32768)
AT91C_BASE_PMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x05) |
(AT91C_CKGR_PLLCOUNT & (28<<8)) |
(AT91C_CKGR_MUL & (29<<16)));
// Wait the startup time
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK));
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
// 4. Selection of Master Clock and Processor Clock
// select the PLL clock divided by 2
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK ;
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
}
//-------------------------------------------------------------
void InitPeriphery(void)
{
//enable the clock of the PIO
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US1;
// GPIO init
AT91C_BASE_PIOA->PIO_ODR = 0xffffffff; // All as input
//configure the PIO Lines corresponding to LEDs
//Enable pins
AT91C_BASE_PIOA->PIO_PER = LED0 | LED1 | LED2 | LED3 | USB_ON;
//Configure in Output
AT91C_BASE_PIOA->PIO_OER = LED0 | LED1 | LED2 | LED3 | USB_ON;
//set reg to 1
AT91C_BASE_PIOA->PIO_SODR = LED0 | LED1 | LED2 | LED3 | USB_ON;
//Enable RESET
AT91C_BASE_RSTC->RSTC_RCR = 0xA5000008;
AT91C_BASE_RSTC->RSTC_RMR = 0xA5000001;
}
//------------------------------------------------------------------------------
/// Configures USART0 in hardware handshaking mode, asynchronous, 8 bits, 1 stop
/// bit, no parity, 115200 bauds and enables its transmitter and receiver.
//------------------------------------------------------------------------------
void ISR_Usart1(void)
{
unsigned int status;
// Read USART status
status = AT91C_BASE_US1->US_CSR;
status&=AT91C_BASE_US1->US_IMR;
AT91C_BASE_PIOA->PIO_CODR = LED1 | LED2;
//MyDelay(500000);
for (int k=0;k<100000;k++)
{
}
AT91C_BASE_PIOA->PIO_SODR = LED1 | LED2;
for (int k=0;k<100000;k++)
{
}
}
void ConfigureUsart1(void)
{
unsigned int mode = AT91C_US_USMODE_NORMAL
| AT91C_US_CLKS_CLOCK
| AT91C_US_CHRL_8_BITS
| AT91C_US_PAR_NONE
| AT91C_US_NBSTOP_1_BIT
| AT91C_US_CHMODE_NORMAL;
// Enable the peripheral clock in the PMC
PMC_EnablePeripheral(AT91C_ID_US1);
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US1;
// Configure the USART in the desired mode @115200 bauds
USART_Configure(AT91C_BASE_US1, mode, 115200, BOARD_MCK);
AT91C_BASE_US1->US_TTGR=0;
// Configure the RXBUFF interrupt
AIC_ConfigureIT(AT91C_ID_US1, 0, ISR_Usart1);
AIC_EnableIT(AT91C_ID_US1);
// Enable receiver & transmitter
USART_SetTransmitterEnabled(AT91C_BASE_US1, 1);
USART_SetReceiverEnabled(AT91C_BASE_US1, 1);
}
//-------------------------------------------------------------
void MyDelay(unsigned long a)
{
volatile unsigned long d;
d=a;
while (--d!=0);
}
//-------------------------------------------------------------
int main()
{
// Freq init
InitFrec();
// Init periphery
InitPeriphery();
AT91C_BASE_PIOA->PIO_PDR=(1<<5)|(1<<6)|(1<<8)|(1<<9);
AT91C_BASE_PIOA->PIO_ASR=(1<<5)|(1<<6)|(1<<8)|(1<<9);
AT91C_BASE_PIOA->PIO_BSR=0;
ConfigureUsart1();
AT91C_BASE_US1->US_IER = AT91C_US_ENDRX;
AT91C_BASE_PIOA->PIO_CODR = LED1 | LED2;
MyDelay(500000);
AT91C_BASE_PIOA->PIO_SODR =LED1 | LED2;
MyDelay(500000);
AT91C_BASE_PIOA->PIO_CODR = LED0 | LED1 | LED2 | LED3;
MyDelay(500000);
AT91C_BASE_PIOA->PIO_SODR = LED0 | LED1 | LED2 | LED3;
MyDelay(500000);
while(!(AT91C_BASE_US1->US_CSR&AT91C_US_TXRDY)==1);
AT91C_BASE_US1->US_THR=((0xff&0x1ff));
USART_Write(AT91C_BASE_US1,0xCC,1);
AT91C_BASE_US1->US_THR=0xff;
while(1);
}
//-------------------------------------------------------------
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\aic\aic.h"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\aic\aic.c"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\usart\usart.c"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\usart\usart.h"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\pmc\pmc.c"
#include "$PROJ_DIR$\..\..\..\at91lib\peripherals\pmc\pmc.h"
//-------------------------------------------------------------
//bits
#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define BIT4 0x00000010
#define BIT5 0x00000020
#define BIT6 0x00000040
#define BIT7 0x00000080
#define BIT8 0x00000100
#define BIT9 0x00000200
#define BIT10 0x00000400
#define BIT11 0x00000800
#define BIT12 0x00001000
#define BIT13 0x00002000
#define BIT14 0x00004000
#define BIT15 0x00008000
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define BIT23 0x00800000
#define BIT24 0x01000000
#define BIT25 0x02000000
#define BIT26 0x04000000
#define BIT27 0x08000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000
/// Frequency of the board main oscillator.
#define BOARD_MAINOSC 16000000
/// Master clock frequency (when using board_lowlevel.c).
#define BOARD_MCK 48000000
#define LED0 BIT25
#define LED1 BIT22
#define LED2 BIT24
#define LED3 BIT23
#define USB_ON BIT7
/// Maximum Bytes Per Second (BPS) rate that will be forced using the CTS pin.
#define MAX_BPS 500
/// Size of the receive buffer used by the PDC, in bytes.
#define BUFFER_SIZE 1
/// Number of bytes received between two timer ticks.
volatile unsigned int bytesReceived = 0;
/// Receive buffer.
unsigned char pBuffer[BUFFER_SIZE];
/// String buffer.
char pString[24];
//-------------------------------------------------------------
void InitFrec(void)
{
// Set Flash Waite sate - Flash Memory Controler
// if MCK = 47923200 I have 50 Cycle for 1 usecond
AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN)&(48 <<16)) | AT91C_MC_FWS_1FWS;
// Watchdog Disable
AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
// 1 Enabling the Main Oscillator:
// SCK = 1/32768 = 30.51 uSecond
// Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
AT91C_BASE_PMC->PMC_MOR =
(( AT91C_CKGR_OSCOUNT & (0x06 <<8) | AT91C_CKGR_MOSCEN ));
// Wait the startup time
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
// 2 Checking the Main Oscillator Frequency (Optional)
// 3 Setting PLL and divider:
// - div by 5 Fin = 3,2 = (16,000 / 5)
// - Mul 29+1: Fout = 96,0 = (3,2 * 30)
// for 96 MHz the erroe is 0.0%
// Field out NOT USED = 0
// PLLCOUNT pll startup time estimate at : 0.844 ms
// PLLCOUNT 28 = 0.000844 /(1/32768)
AT91C_BASE_PMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x05) |
(AT91C_CKGR_PLLCOUNT & (28<<8)) |
(AT91C_CKGR_MUL & (29<<16)));
// Wait the startup time
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK));
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
// 4. Selection of Master Clock and Processor Clock
// select the PLL clock divided by 2
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK ;
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
}
//-------------------------------------------------------------
void InitPeriphery(void)
{
//enable the clock of the PIO
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US1;
// GPIO init
AT91C_BASE_PIOA->PIO_ODR = 0xffffffff; // All as input
//configure the PIO Lines corresponding to LEDs
//Enable pins
AT91C_BASE_PIOA->PIO_PER = LED0 | LED1 | LED2 | LED3 | USB_ON;
//Configure in Output
AT91C_BASE_PIOA->PIO_OER = LED0 | LED1 | LED2 | LED3 | USB_ON;
//set reg to 1
AT91C_BASE_PIOA->PIO_SODR = LED0 | LED1 | LED2 | LED3 | USB_ON;
//Enable RESET
AT91C_BASE_RSTC->RSTC_RCR = 0xA5000008;
AT91C_BASE_RSTC->RSTC_RMR = 0xA5000001;
}
//------------------------------------------------------------------------------
/// Configures USART0 in hardware handshaking mode, asynchronous, 8 bits, 1 stop
/// bit, no parity, 115200 bauds and enables its transmitter and receiver.
//------------------------------------------------------------------------------
void ISR_Usart1(void)
{
unsigned int status;
// Read USART status
status = AT91C_BASE_US1->US_CSR;
status&=AT91C_BASE_US1->US_IMR;
AT91C_BASE_PIOA->PIO_CODR = LED1 | LED2;
//MyDelay(500000);
for (int k=0;k<100000;k++)
{
}
AT91C_BASE_PIOA->PIO_SODR = LED1 | LED2;
for (int k=0;k<100000;k++)
{
}
}
void ConfigureUsart1(void)
{
unsigned int mode = AT91C_US_USMODE_NORMAL
| AT91C_US_CLKS_CLOCK
| AT91C_US_CHRL_8_BITS
| AT91C_US_PAR_NONE
| AT91C_US_NBSTOP_1_BIT
| AT91C_US_CHMODE_NORMAL;
// Enable the peripheral clock in the PMC
PMC_EnablePeripheral(AT91C_ID_US1);
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US1;
// Configure the USART in the desired mode @115200 bauds
USART_Configure(AT91C_BASE_US1, mode, 115200, BOARD_MCK);
AT91C_BASE_US1->US_TTGR=0;
// Configure the RXBUFF interrupt
AIC_ConfigureIT(AT91C_ID_US1, 0, ISR_Usart1);
AIC_EnableIT(AT91C_ID_US1);
// Enable receiver & transmitter
USART_SetTransmitterEnabled(AT91C_BASE_US1, 1);
USART_SetReceiverEnabled(AT91C_BASE_US1, 1);
}
//-------------------------------------------------------------
void MyDelay(unsigned long a)
{
volatile unsigned long d;
d=a;
while (--d!=0);
}
//-------------------------------------------------------------
int main()
{
// Freq init
InitFrec();
// Init periphery
InitPeriphery();
AT91C_BASE_PIOA->PIO_PDR=(1<<5)|(1<<6)|(1<<8)|(1<<9);
AT91C_BASE_PIOA->PIO_ASR=(1<<5)|(1<<6)|(1<<8)|(1<<9);
AT91C_BASE_PIOA->PIO_BSR=0;
ConfigureUsart1();
AT91C_BASE_US1->US_IER = AT91C_US_ENDRX;
AT91C_BASE_PIOA->PIO_CODR = LED1 | LED2;
MyDelay(500000);
AT91C_BASE_PIOA->PIO_SODR =LED1 | LED2;
MyDelay(500000);
AT91C_BASE_PIOA->PIO_CODR = LED0 | LED1 | LED2 | LED3;
MyDelay(500000);
AT91C_BASE_PIOA->PIO_SODR = LED0 | LED1 | LED2 | LED3;
MyDelay(500000);
while(!(AT91C_BASE_US1->US_CSR&AT91C_US_TXRDY)==1);
AT91C_BASE_US1->US_THR=((0xff&0x1ff));
USART_Write(AT91C_BASE_US1,0xCC,1);
AT91C_BASE_US1->US_THR=0xff;
while(1);
}
//-------------------------------------------------------------
Проект переделывал из стандартного ИАРовского.
Это одна из многих модификаций,кардинальных различий в них нету,как и в их работе(во всех случаях на Rx есть данные,но прерывания не запускаются)
Мучаюсь с армом 4ый день
