реклама на сайте
подробности

 
 
> Использование USART в AT91SAM7X256
zoddy
сообщение Sep 16 2009, 09:24
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 42
Регистрация: 4-12-05
Из: Екатеринбург
Пользователь №: 11 773



Доброго времени суток!

Пытаюсь изучать ARMы. Имеется отладочная плата-аналог AT91SAM7x-EK. Имеется SAM-ICE. Работаю в IAR EW-ARM 5.40.
Использую немного модифицированный пример из IARa "basic-usart-hw-handshaking-project"

Код
/*Headers */

#include <board.h>
#include <pio/pio.h>
#include <pio/pio_it.h>
#include <aic/aic.h>
#include <usart/usart.h>
#include <tc/tc.h>
#include <led.h>
#include <stdio.h>
//#include "JLINKDCC.h"

/* Defines*/
/// Delay for pushbutton debouncing (in milliseconds).
#define DEBOUNCE_TIME       500

/// PIT period value in µseconds.
#define PIT_PERIOD          1000


/*Global variables*/
const Pin pinPB1 = PIN_PUSHBUTTON_1;
const Pin pinPB2 = PIN_PUSHBUTTON_2;
const Pin pinPB3 = PIN_PUSHBUTTON_3;
const Pin pinPB4 = PIN_PUSHBUTTON_4;

static int result;

/// 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         2

/// Pins to configure for the application.
const Pin pins[] = {
    PINS_DBGU,
    PIN_USART0_RXD,
    PIN_USART0_TXD,
    PIN_USART0_CTS,
    PIN_USART0_RTS
};

/// 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];

/* Interrupt handlers*/

//------------------------------------------------------------------------------
/// Interrupt handler for USART0. Increments the number of bytes received in the
/// current second and starts another transfer if the desired bps has not been
/// met yet.
//------------------------------------------------------------------------------
void ISR_Usart0(void)
{//
    unsigned int status;

    // Read USART status
    status = AT91C_BASE_US0->US_CSR;

    // Receive buffer is full
    if ((status & AT91C_US_RXBUFF) == AT91C_US_RXBUFF)
    {
        LED_Set(0);
        USART_ReadBuffer(AT91C_BASE_US0, pBuffer, BUFFER_SIZE);
        USART_WriteBuffer(AT91C_BASE_US0, pBuffer, BUFFER_SIZE);              
    }
}

void ConfigureButtons(void)
{//
    
#if defined(at91sam7lek)
    const Pin pinCol0 = PIN_KEYBOARD_COL0;
    PIO_Configure(&pinCol0, 1);
#endif
    
#if defined(at91cap9dk)
    const Pin pinRow0 = PIN_KEYBOARD_ROW0;
    PIO_Configure(&pinRow0, 1);
#endif
    
    // Configure pios
    PIO_Configure(&pinPB1, 1);
    PIO_Configure(&pinPB2, 1);
    PIO_Configure(&pinPB3, 1);
    PIO_Configure(&pinPB4, 1);  
    
    // Initialize interrupts
    //  PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    //  PIO_ConfigureIt(&pinPB1, (void (*)(const Pin *)) ISR_Bp1);
    //  PIO_ConfigureIt(&pinPB2, (void (*)(const Pin *)) ISR_Bp2);
    //  PIO_ConfigureIt(&pinPB3, (void (*)(const Pin *)) ISR_Bp3);
    //  PIO_ConfigureIt(&pinPB4, (void (*)(const Pin *)) ISR_Bp4);
    //
    //  PIO_EnableIt(&pinPB1);
    //  PIO_EnableIt(&pinPB2);
    //  PIO_EnableIt(&pinPB3);
    //  PIO_EnableIt(&pinPB4);
    
}

void ConfigureLeds(void)
{//
    LED_Configure(0);
    LED_Configure(1);
    LED_Configure(2);
    LED_Configure(3);
}


//------------------------------------------------------------------------------
/// Configures USART0 in hardware handshaking mode, asynchronous, 8 bits, 1 stop
/// bit, no parity, 115200 bauds and enables its transmitter and receiver.
//------------------------------------------------------------------------------
void ConfigureUsart0(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_US0);

    // Configure the USART in the desired mode @115200 bauds
    USART_Configure(AT91C_BASE_US0, mode, 115200, BOARD_MCK);

    // Configure the RXBUFF interrupt
    AIC_ConfigureIT(AT91C_ID_US0, 0, ISR_Usart0);
    AIC_EnableIT(AT91C_ID_US0);

    // Enable receiver & transmitter
    USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
    USART_SetReceiverEnabled(AT91C_BASE_US0, 1);
}

/* Main */
int main()
{
    ConfigureLeds();    
    ConfigureButtons();
    ConfigureUsart0();    
    
    // Start receiving data and start timer
    USART_ReadBuffer(AT91C_BASE_US0, pBuffer, BUFFER_SIZE);
    AT91C_BASE_US0->US_IER = AT91C_US_RXBUFF;
    TC_Start(AT91C_BASE_TC0);      

    while (1);
    return 0;
}


Проблема состоит в следующем. Я передаю с ПК последовательность байт по RS-232. Данная последовательность ARMом принимается, что видно по зажиганию светодиода Led0 , а вот назад с ARMa почему-то ничего не идет. :-( В чем может быть причина?

И сопутствующий вопрос к знатокам IARa... возможно ли как то изменять состояние регистров и ячеек памяти при отладке через JTAG? В свое время пользовался такой функцией в AVRStudio... очень было удобно!

И еще одна убедительная просьба, сильно не критиковать за какие либо ляпы в моем вопросе... я ведь только начинаю;-)
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
Sergey'F
сообщение Sep 17 2009, 07:11
Сообщение #2


Местный
***

Группа: Свой
Сообщений: 351
Регистрация: 17-09-05
Из: Москва
Пользователь №: 8 660



Честно говоря, весь код раскапывать тяжко.
Для начала вопрос - сигнал на ножке TX есть? В контроллере PIOA настроены ножки USART соответствующим образом?
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 21st July 2025 - 16:27
Рейтинг@Mail.ru


Страница сгенерированна за 0.01476 секунд с 7
ELECTRONIX ©2004-2016