same70 x plained problems with usart

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone, I am new with is type of products and I am a bit lost.

 

I am trying to implement a USART communication between the pc and the board, but I can not have it, I can not send or received anything.

 

Can you help me to solve this problem??

 

This is my code, I do not know if I have to change any .c file or anything else ( I am thinking in changing the direction of the ports but I do not know how to do it)

 

#include <asf.h>

 

 

int main (void)
{
    /* Insert system clock initialization code here (sysclk_init()). */

 

    board_init();
    sysclk_init();
    ioport_init();
    
    gpio_set_pin_low(LED0_GPIO);
    delay_ms(100);
    
    gpio_set_pin_high(LED0_GPIO);
    delay_ms(100);
    gpio_set_pin_low(LED0_GPIO);
    delay_ms(100);
    gpio_set_pin_high(LED0_GPIO);
    delay_ms(100);
    gpio_set_pin_low(LED0_GPIO);
    delay_ms(100);
    gpio_set_pin_high(LED0_GPIO);
    delay_ms(100);
    gpio_set_pin_low(LED0_GPIO);
    delay_ms(100);
    gpio_set_pin_high(LED0_GPIO);
    delay_ms(100);
    
    /* Set output direction on the given LED IOPORTs */
    ioport_set_pin_dir(PIO_PC19_IDX, IOPORT_DIR_OUTPUT);
    ioport_set_pin_dir(PIO_PA2_IDX, IOPORT_DIR_OUTPUT);  
  
    pmc_enable_periph_clk(ID_USART1);
     
    const sam_usart_opt_t usart_console_settings = {CONF_UART_BAUDRATE,CONF_UART_CHAR_LENGTH, CONF_UART_PARITY,CONF_UART_STOP_BITS,US_MR_CHMODE_NORMAL};

    sysclk_enable_peripheral_clock(CONF_UART);
    
 
    usart_init_rs232(CONF_UART, &usart_console_settings, sysclk_get_peripheral_hz());
 

    usart_enable_tx(CONF_UART);
    usart_enable_rx(CONF_UART);
    

    
    ///* Configure and enable interrupt of USART. */
    //NVIC_EnableIRQ(USART1_IRQn);
       
    //-------------------------------------------------------------------------------------------------
    while(1)
    {
        gpio_set_pin_low(LED0_GPIO);
        gpio_set_pin_high(PIO_PC19_IDX);
        gpio_set_pin_high(PIO_PA2_IDX);
        
        usart_write(CONF_UART,75);
        
        delay_ms(1000);
        gpio_set_pin_high(LED0_GPIO);
        gpio_set_pin_low(PIO_PC19_IDX);
        gpio_set_pin_low(PIO_PA2_IDX);
        delay_ms(1000);
    }
    
}

 

As you can see, I have 3 leds blinking to know that everything is running, and I am constantly sending data (75) on USART1, if I am not wrong, PB4D but I see nothing. When this works I want to put the usart_read function to send the same I have received, but now I have nothig.

 

Any idea of what is happening?

 

Thank you

Last Edited: Wed. Apr 11, 2018 - 10:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At the end I have found a solution.....

 

I added on  board_init() the following code and it starts transmiting...

 

#ifndef CONF_BOARD_H_INCLUDED
#define CONF_BOARD_H_INCLUDED

/* Enable ICache and DCache */
#define CONF_BOARD_ENABLE_CACHE

/** Enable Com Port. */
#define CONF_BOARD_UART_CONSOLE

/* USART0 module is used in SYNC. mode. */
#define CONF_BOARD_USART_RXD
#define CONF_BOARD_USART_TXD
#define CONF_BOARD_USART_SCK
#define CONF_BOARD_USART_CTS

#endif /* CONF_BOARD_H_INCLUDED */

 

Now I will see if I can also received