Code: Select all
/**
* Any initialization code needed for MCU to function properly.
* Do not remove this line or clock might not be set correctly.
*/
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif
//include files and opjects for UART
#include "MikroSDK.Hal.UART"
static hal_uart_t hal_uart;
// UART HAL config structure
static hal_uart_config_t hal_uart_cfg;
// Be careful to have large enough buffers
static uint8_t uart_rx_buffer[128];
// Be careful to have large enough buffers
static uint8_t uart_tx_buffer[128];
static size_t size;
//initialization function of UART
void application_init_uart ( void )
{
// Fill structure with default values
hal_uart_configure_default( &hal_uart_cfg );//uart_configure_default( &uart_cfg );
// Specify desired UART RX pin
hal_uart_cfg.rx_pin = PA10;
// Specify desired UART TX pin
hal_uart_cfg.tx_pin = PA9;
// Declare buffer size
hal_uart_cfg.tx_ring_size = sizeof(uart_tx_buffer);
// Declare buffer size
hal_uart_cfg.rx_ring_size = sizeof(uart_rx_buffer);
if ( hal_uart_open( &hal_uart.handle, true ) == HAL_UART_ERROR )
{
// Error handling strategy
}
}
int main(void)
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init_uart ();
while (1)
{
size = hal_uart_println( &hal_uart.handle, "Hello!" ); // Print out "Hello!" with new line every second.
Delay_ms(1000);
}
return 0;
}
-Second how can i use interrupt receive on rx pin ?
please MikroE team i have been trying for almost three days with no success please any help i have searched also Mikrosdk help but it doesn't contain any working example. I have also attached the project folder.
kind regards,
Sam