cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help to understand this code

Asraful
Associate III

this is code from an Udemy tutorial but i couldn't get the part of 9 bit data transfer with no parity bit can anyone help me to understand that please

 

Screenshot 2023-10-12 195942.png

18 REPLIES 18

Here is the problem I couldn't find someone thats why i am here 

Asraful
Associate III

is there any discord channel or anything like that where i can talk with someone to clear this problem 

ST uses casting as it's C, and they only want to implement one universal function.

Most people aren't using 9-bit mode, and those using parity its somewhat invisible.

9-bit mode is most often used where you're trying to differentiate data from a command/control channel. ie the additional bit flags as to whether the byte should be processed as data, or handled specially as a command. Sometimes used on 8051 in multi-processor mode, a special byte in the stream indicates the MCU you wish to address, whilst the other bytes you want the MCU to consume into it's buffers. ie a very simplistic networking protocol, where there's a constant stream of data, and you want ONE to cherry pick specific blocks of bytes.

If you're not using 9-bit data forms, perhaps stop getting hung up on this, and come back to it when the need or reasoning becomes more apparent. Perhaps look at more examples of pointers and casting, and why they might be useful.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MM..1
Chief II

You dont show config your handle and asked code is very clean commented. 

Respectfully, if you've spent 7 days on this, perhaps look more into basic C tutorials. It can be complicated, but casts from pointers to uint8_t and uint16_t should be straightforward. Understand how the data is laid out in memory and how the compiler interprets it based on the type of pointer.

Or perhaps improve the question. You say you're following a tutorial. Which one? Provide a link. Provide relevant usage code. How does it initialize the array? How does it call the function?

If you feel a post has answered your question, please click "Accept as Solution".

>is there any discord channel or anything like that where i can talk with someone to clear this problem 

Here you can find a friendly soul: https://www.fiverr.com/categories/programming-tech/electronics-engineering/embedded-systems-iot

For general programming techniques, learning C -

https://www.fiverr.com/categories/programming-tech/software-development/help-consultation

 

Eddiie
Associate II

I think I am running into something similar to this.  

First time for me in MCP and 9bit mode.  Blowing my mind.

I just picked up STM32 CubeIDE... been reading so many different links, articles, demos, I think it has caused me to forget some basics.  ha

 

I want to send a 9 bit byte.    I'm in 9 bit mode..

uint8_t tx_buff[]={270,66,67,68,69,70,71,72,73,74}; //0x10E BCDEFGHIJ in ASCII code

In case you missed it, the first element is larger than 8 bits...

The send -

HAL_UART_Transmit_IT(&huart1, tx_buff, 10);

 

HAL_UART_Transmit_IT(&huart1, tx_buff, 10);

 

 

I get a compiler warning, of course, saying it doesn't like my 270.

 

Duh.   OK,  let's make it uint16_t

 

uint16_t tx_buff[]={270,66,67,68,69,70,71,72,73,74}; //0x10E BCDEFGHIJ in ASCII code

 

 

 

New warning -

 

 

Description	Resource	Path	Location	Type
passing argument 2 of 'HAL_UART_Transmit_IT' from incompatible pointer type [-Wincompatible-pointer-types]	main.c	/Olimex_Eval_STM32-P152_Try2/Core/Src	line 118	C/C++ Problem

 

 

 

How do I send a 9bit .. byte?   I actually haven't test it yet.  Was hoping to find a nice working example somewhere of MCP Master and Slave.

 

Eddiie
Associate II

I look up the function HAL_UART_Transmit_IT...

 

It says -

/**
  * @brief  Sends an amount of data in non blocking mode.
  * @note   When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
  *         the sent data is handled as a set of u16. In this case, Size must indicate the number
  *         of u16 provided through pData.
  * @PAram  huart Pointer to a UART_HandleTypeDef structure that contains
  *               the configuration information for the specified UART module.
  * @PAram  pData Pointer to data buffer (u8 or u16 data elements).
  * @PAram  Size  Amount of data elements (u8 or u16) to be sent
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size)

pData is still uint8_t  ............. 

 

../Drivers/STM32L1xx_HAL_Driver/Inc/stm32l1xx_hal_uart.h:747:82: note: expected 'const uint8_t *' {aka 'const unsigned char *'} but argument is of type 'uint16_t *' {aka 'short unsigned int *'}

const uint16_t tx_buff[]={270,66,67,68,69,70,71,72,73,74}; //0x10E BCDEFGHIJ in ASCII code

Adding const didn't help.

hehe

 

Eddiie
Associate II