Sam4e16e Handshaking hw USART PDC TX

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

gabrielcuellar
Posts: 12
Joined: Tue Apr 28, 2015 4:55 pm

Sam4e16e Handshaking hw USART PDC TX

Tue Apr 28, 2015 5:49 pm

Hi everyone!!!

I need can drives my data through of my USART1 with the handshaking hw mode, for that I need the PDC. The problem is, I don`t know how to transmitted a data with the PDC or USART, in the USART I can find functions like usart_write(), usart_write_line(), usart_putchar(); but this function does´nt work like I hope. The example of ECO no help me for I want to do.
#include <asf.h>

#define USART_SERIAL USART1
#define USART_SERIAL_ID ID_USART1 //USART0 for sam4l
#define USART_SERIAL_BAUDRATE 115200 * 2 //en la funcion "usart_set_async_baudrate" reemplazar formula cd_fp = (8 * ul_mck + (over * baudrate)) / (over * baudrate)
#define USART_SERIAL_CHAR_LENGTH US_MR_CHRL_8_BIT
#define USART_SERIAL_PARITY US_MR_PAR_NO
#define USART_SERIAL_STOP_BIT US_MR_NBSTOP_1_BIT

uint32_t received_byte;
int main (void)
{
sysclk_init();
board_init();

const sam_uart_opt_t uart_console_setting=
{sysclk_get_cpu_hz(),115200,UART_MR_PAR_NO};


const sam_usart_opt_t usart_console_settings = {
USART_SERIAL_BAUDRATE,
USART_SERIAL_CHAR_LENGTH,
USART_SERIAL_PARITY,
USART_SERIAL_STOP_BIT,
US_MR_CHMODE_NORMAL
};


pmc_enable_periph_clk(ID_PIOA);
sysclk_enable_peripheral_clock(ID_PIOA);
pmc_enable_periph_clk(ID_UART0);
sysclk_enable_peripheral_clock(ID_USART1);

pio_configure(PINS_UART0_PIO,PINS_UART0_TYPE,PINS_UART0_MASK,PINS_UART0_ATTR);//Configuracion de los pines de la UART0

pio_configure(PIOA,PIO_PERIPH_A,(PIO_PA25A_CTS1|PIO_PA26A_DCD1|PIO_PA28A_DSR1|PIO_PA27A_DTR1|PIO_PA29A_RI1|PIO_PA24A_RTS1|PIO_PA21A_RXD1|PIO_PA23A_SCK1|PIO_PA22A_TXD1),PIO_DEFAULT);//Configuracion de los pines de la USART1 PIO_PA21A_RXD1 | PIO_PA22A_TXD1
//pio_set_output(PIOA,PIO_PA22,HIGH,DISABLE,DISABLE);//TX
//pio_set_output(PIOA,PIO_PA24,LOW,DISABLE,DISABLE);//RTS
//pio_set_input(PIOA,PIO_PA25,PIO_PULLUP);//CTS
//pio_set_input(PIOA,PIO_PA21,PIO_PULLUP);//RX


pio_set_output(PIOA,PIO_PA23,LOW,DISABLE,DISABLE);//Bajo la linea del Transceiver RS232

uart_init(UART0,&uart_console_setting);

usart_init_hw_handshaking(USART1, &usart_console_settings,sysclk_get_main_hz());

usart_enable_tx(USART_SERIAL);
usart_enable_rx(USART_SERIAL);

uint8_t i;


uint8_t GLB_BUFFER_PDC[5]={'H','O','L','A'};
pdc_packet_t GLB_PACK_PDC;
Pdc *GLB_PTR_PDC;

GLB_PTR_PDC = usart_get_pdc_base(USART1);
GLB_PACK_PDC.ul_addr = (uint32_t)GLB_BUFFER_PDC;
GLB_PACK_PDC.ul_size = 11;

pdc_enable_transfer(GLB_PTR_PDC, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);
pdc_rx_init(GLB_PTR_PDC, &GLB_PACK_PDC, NULL);
pdc_tx_init(GLB_PTR_PDC, &GLB_PACK_PDC, NULL);

uart_enable_interrupt(USART1,US_IER_RXBUFF | US_IER_TXRDY);// //US_IER_RXRDY
NVIC_EnableIRQ(USART1_IRQn);

//usart_drive_RTS_pin_high(USART1);
//usart_drive_RTS_pin_low(USART1);
uint32_t caracter = 'A';


while(1)
{
delay_ms(2);
usart_write(USART1, caracter);
delay_ms(2);
usart_write_line(USART1,"Texto de prueba \nOk!!!");
delay_ms(2);
usart_putchar(USART1, caracter);
//while(usart_read(USART1,&received_byte));
}
}

void USART1_Handler(void)
{
uint32_t var_status = usart_get_status(USART1);
if ((var_status & US_CSR_RXRDY)== US_CSR_RXRDY)
{
usart_drive_RTS_pin_high(USART1);
while(usart_write(USART1,received_byte));

}
}

//if(uart_is_rx_ready(UART0)){
//
// while(uart_write(UART0,i));
// }

//if(usart_is_rx_ready(USART1)){
//while(usart_read(USART1,&received_byte));
//usart_drive_RTS_pin_low(USART1);
//sprintf (comando_gprs,"%c%d%s",ESPERAR_OK,1500,"AT");usart_write_line(USART1,(char *)buff);
//usart_drive_RTS_pin_high(USART1);
//}
gabrielcuellar
Posts: 12
Joined: Tue Apr 28, 2015 4:55 pm

Re: Sam4e16e Handshaking hw USART PDC TX

Tue Apr 28, 2015 8:13 pm

The solution was the control lines CTS and RTS I no controlled, this two lines must be in Zero for the transmition. The before code and the functions work perfectly :) :) :)

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest