ARM Embedded Tutorial - Raspberry Pi Pico saying Hello via UART

From Free Pascal wiki
Revision as of 01:09, 1 March 2021 by MiR (talk | contribs)
Jump to navigationJump to search

English (en)

The next peripheral on the tutorial list is the UART.


program uart;
{$MODE OBJFPC}
{$H+}

uses
  pico_uart_c,
  pico_gpio_c,
  pico_timer_c;
const
  BAUD_RATE=115200;
begin
  gpio_init(TPicoPin.LED);
  gpio_set_dir(TPicoPin.LED,TGPIODirection.GPIO_OUT);
  uart_init(uart0, BAUD_RATE);
  gpio_set_function(TPicoPin.GP0_UART0_TX, TGPIOFunction.GPIO_FUNC_UART);
  gpio_set_function(TPicoPin.GP1_UART0_RX, TGPIOFunction.GPIO_FUNC_UART);
  repeat
    gpio_put(TPicoPin.LED,true);
    uart_puts(uart0, 'Hello, UART!'+#13+#10);
    busy_wait_us_32(500000);
    gpio_put(TPicoPin.LED,false);
    busy_wait_us_32(500000);
  until 1=0;
end.

One notable change is that you may have seen that we do not provide __aeabi_uidiv anymore, instead we link to libgcc.a and get (hopefully) best possible performance for the unsigned integer division.

This application is best tested with picoprobe, when you connect it to your development board as described in the Getting Started Guide chapter then the GPIO pins 0 and 1 are connected to the debug probe which makes them visible as a serial interface on your computer.

Connect your terminal program to the UART port and enjoy the message from your Pico.

Back to main Pico Page