Sunday, January 1, 2017

One char after another...

I started the work to onewire library, to test the DS18B20 temperature sensor but realized that I don't know yet how to work with the serial transmission :(. So, I opened the STM32CubeMX for the configuration of a new project that will use the main serial port of the Arduino socket (on my Nucleo board, of course). And, after generating the configuration, you have to look for the HAL API documentation to realize which transmit function you can use.

Of course it didn't worked for the first try, because instead of UART function, I used USART function. It didn't worked until I changed to:

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData,
                        uint16_t Size, uint32_t Timeout)

But now is ok. See the code in repository. In future, I will try the interrupt based functions as I need them for a more advanced program.

BTW, I changed the automatically generated UART init function regarding the mode (transmit only)and this, only because I didn't knew how to make this from the STM32CubeMX interface. Now I know.

/* USART2 init function */
static void MX_USART2_UART_Init(void)
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 38400;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)

No comments:

Post a Comment