cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit ?

antonius
Senior
Posted on September 28, 2015 at 22:58

Guys,

How can I transmit a variable value using HAL_UART_Transmit ?

for example I have

c = 0;

How can I do :

HAL_UART_Transmit(&huart1, c, 100, 1000); and I will get 0 on my serial port

?

Thanks

6 REPLIES 6
Posted on September 29, 2015 at 01:01

Doesn't it use pointers? Is c an array 100 bytes deep?

You want the values in binary, or converted to ASCII?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on September 29, 2015 at 04:04

c is a hex character taken from register, I want to see its value,

Yes I want it converted to ASCII, how to do that ?

thanks

===================

Doesn't it use pointers? Is c an array 100 bytes deep?

You want the values in binary, or converted to ASCII?

antonius
Senior
Posted on September 29, 2015 at 14:21

I have the code :

while(Mp3ReadRegister(0x03) != CLOCK_REG)

and I want to display CLOCK_REG into HAL_usart_transmit....how can I do that ? it's not working with : HAL_UART_Transmit(&huart1, CLOCK_REG, 100, 1000);
antonius
Senior
Posted on September 29, 2015 at 15:33

I want to make like this, it's on AVR :

void usart_transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) )
;
/* Put data into buffer, sends the data */
UDR0 = data;
}

How can I make it similar in STM..? Thanks
Posted on September 29, 2015 at 17:56

You don't seem to understand the concept of passing as a pointer vs passing as a value.

A pointer is the address of something, the HAL routines want an address of a buffer, with a specified length.

Are you familiar with itoa() and sprintf(), perhaps you can use those to form the binary data into an ASCII form, in a buffer, and then provide that buffer to the HAL?

char str[32];

sprintf(str, ''%d'', CLOCK_REG); // As a value

HAL_UART_Transmit(&huart1, str, strlen(str), 1000); // As a pointer, with a length

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on September 30, 2015 at 00:00

Ok, I'll give a try

The result : CLOCK_REG Value: ..%d.. The code :

HAL_UART_Transmit(&huart1, ''CLOCK_REG Value:

'', 100, 1000);
char str[32];
sprintf(str, ''%d'', CLOCK_REG); // As a value

This is what I want to do :

#define CLOCK_REG 0xc000 
unsigned char Mp3ReadRegister( unsigned char addressbyte)
{
int resultvalue = 0;
Mp3DeselectData();
Mp3SelectControl(); //XCS = 0
uint8_t data7[2] = { VS_READ_COMMAND, addressbyte };
HAL_SPI_Transmit_DMA(&hspi1,data7,2); 
//SPIPutChar(VS_READ_COMMAND); //????????
//SPIPutChar(addressbyte); //????????
uint8_t data8[1] = {0x00};
resultvalue = HAL_SPI_Receive_DMA(&hspi1, data8, 1) << 8; //is it the same with I have commented out ?
resultvalue |= HAL_SPI_Receive_DMA(&hspi1, data8, 1); //
//resultvalue = SPIGetChar() << 8;//???8???
//resultvalue |= SPIGetChar(); //???8???
Mp3DeselectControl(); 
return resultvalue; //??16??????
}
then :
while(Mp3ReadRegister(0x03) != CLOCK_REG)

I want to check the value of CLOCK_REG inside the chip = ? Any clues ? thanks