STM32CubeMx HAL_SPI_Receive ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-06 02:59 PM
Guys,
I want to send a command and then retrieve the output on MOSI line ... Is the right way doing it ?int resultvalue = 0;
uint8_t data7[2] = { VS_READ_COMMAND, addressbyte };
HAL_SPI_Transmit(&hspi1,data7,2,1000);
then :
uint8_t data8[1] = {0x00}; <=== is it declared properly ?
resultvalue = HAL_SPI_Receive(&hspi1,data8,1,1000);
resultvalue <<= 8;
resultvalue += HAL_SPI_Receive(&hspi1,data8,1,1000);
return resultvalue;
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-17 07:02 AM
Like I said earlier, I think that's a determination you have to make for yourself. The types are at least consistent, and won't lose precision.
The compiler can tell you if the syntax is correct, not if it's functionally correct. I'm not using the HAL or this VS chip, how they interact is something you'll need to experiment with, and review the documentation for. For transmitting, there should be several ways to do it, you might want to check the signals with a logic analyzer to understand if one method has tighter timing, with shorter inter-symbol delays. From: h.rick Posted: Saturday, October 17, 2015 3:10 PM Subject: STM32CubeMx HAL_SPI_Receive ?How about transmiting ?
Am I correct replacing SPIPutchar ?void Mp3WriteRegister(unsigned char addressbyte, unsigned char highbyte, unsigned char lowbyte)
{
Mp3DeselectData();
Mp3SelectControl(); //XCS = 0
uint8_t data6[4] = { 0x02, addressbyte, highbyte, lowbyte };
//uint8_t data6[4] = { VS_WRITE_COMMAND, addressbyte, highbyte, lowbyte };
HAL_SPI_Transmit(&hspi1,data6,4,1000);
//HAL_SPI_Transmit_DMA(&hspi1,data6,4);
/*
SPIPutChar(VS_WRITE_COMMAND); //????????
SPIPutChar(addressbyte); //????????
SPIPutChar(highbyte); //????????8?
SPIPutChar(lowbyte); //????????8?
*/
Mp3DeselectControl();
}
Thanks a lot
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-18 05:53 AM
Please confirm, is this statement similar ?
#define MP3_XCS ( 1 <<
4
)
#define Mp3SelectControl() { GPIOA->ODR &= ~MP3_XCS; }
equal to :
#define Mp3SelectControl() { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4 , 0 ); }
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-18 12:39 PM
With my limited perspective on HAL they would appear to have similar effect.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-24 10:41 PM
Ok, thanks clive,
I have this function :uint16_t Mp3ReadRegister( unsigned char addressbyte)
{
uint16_t resultvalue=0;
Mp3DeselectData();
Mp3SelectControl(); //XCS = 0
uint8_t data7[2] = { VS_READ_COMMAND, addressbyte };
HAL_SPI_Transmit(&hspi1,data7,2,1000);
uint8_t data8[1] = {0x00};
HAL_SPI_Receive(&hspi1,data8,1,1000);
resultvalue = (uint16_t)data8[0] << 8;
HAL_SPI_Receive(&hspi1,data8,1,1000);
resultvalue += (uint16_t)data8[0];
Mp3DeselectControl();
return resultvalue;
}
How can I print
resultvalue
into UART ?
Is it possible with printf(resultvalue) ?
Would it be like this : ?
while(Mp3ReadRegister(0x03) != CLOCK_REG)//�?´Ê±ÖӼĴæÆ÷ //set PLL register
//while(VS1003B_ReadCMD(0x03) != CLOCK_REG)//�?´Ê±ÖӼĴæÆ÷ //set PLL register
{
//check content or register 0x03
uint16_t ReadRegister;
ReadRegister = Mp3ReadRegister(0x03);
sprintf(str, ''%d'', ReadRegister); // As a value
HAL_UART_Transmit(&huart1, str, 100, 1000); // As a pointer, with a length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-25 11:02 AM
uint16_t ReadRegister;
ReadRegister = Mp3ReadRegister(0x03);
sprintf(str, ''%d
'', ReadRegister); // As a value, should also return a length of the output
HAL_UART_Transmit(&huart1, str, strlen(str), 1000); // As a pointer, with a length
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-27 05:34 AM
I get the output like this in my serial....
Anything I must fix ? REGISTER 0x03 = ....... Œ'.... <...X$.È'.<.. ¤..h$..........¢J........ 2192 thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-27 05:39 AM
code :
//Check the content of register and transmit via UART
char str[32];
uint16_t ReadRegister;
ReadRegister = Mp3ReadRegister(0x00);
sprintf(str, ''%d
'', ReadRegister); // As a value, should also return a length of the output
HAL_UART_Transmit(&huart1, ''REGISTER 0x03 =
'', 100, 1000); // As a pointer, with a length
HAL_UART_Transmit(&huart1, str, strlen(str), 1000); // As a pointer, with a length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-27 08:48 AM
You are making my head hurt.
HAL_UART_Transmit(&huart1, ''REGISTER 0x03 =
'', 100, 1000); // As a pointer, with a length
There are NOT 100 characters there, that's why it prints ''REGISTER 0x03 ...'' and then lots of other junk. Constrain the length to that of the actual string you want to send. Or use subroutines. You really need to learn to code.
void Transmit_String(char *s)
{
HAL_UART_Transmit(&huart1, s, strlen(s), 1000); // As a pointer, with a length
}
...
Transmit_String(''REGISTER 0x03 =
'');
Transmit_String(str);
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-27 02:44 PM
HAL_UART_Transmit(&huart1, ''REGISTER 0x03 = \r\n \r\n'', 22, 1000); // As a pointer, with a length
?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-10-27 02:54 PM
Thanks for the suggestion,
Mp3WriteRegister(0x03,0x88,0x10);
HAL_Delay(1000);
//Check the content of register and transmit via UART
char str[32];
uint16_t ReadRegister;
ReadRegister = Mp3ReadRegister(0x03);
sprintf(str, ''%d
'', ReadRegister); // As a value, should also return a length of the output
HAL_UART_Transmit(&huart1, ''REGISTER 0x03 ='', 15, 1000); // As a pointer, with a length
HAL_UART_Transmit(&huart1, str, strlen(str), 1000); // As a pointer, with a length
The output :
REGISTER 0x03 =34832
Is it matter of ASCII and hex format ?
void Mp3WriteRegister(uint8_t addressbyte, uint8_t highbyte, uint8_t lowbyte)
{
Mp3DeselectData();
Mp3SelectControl(); //XCS = 0
uint8_t data6[4] = { VS_WRITE_COMMAND, addressbyte, highbyte, lowbyte };
HAL_SPI_Transmit(&hspi1,data6,4,1000);
Mp3DeselectControl();
}
uint16_t Mp3ReadRegister( unsigned char addressbyte)
{
uint16_t resultvalue=0;
Mp3DeselectData();
Mp3SelectControl(); //XCS = 0
uint8_t data7[2] = { VS_READ_COMMAND, addressbyte };
HAL_SPI_Transmit(&hspi1,data7,2,1000);
uint8_t data8[1] = {0x00};
HAL_SPI_Receive(&hspi1,data8,1,1000);
resultvalue = (uint16_t)data8[0] << 8;
HAL_SPI_Receive(&hspi1,data8,1,1000);
resultvalue += (uint16_t)data8[0];
Mp3DeselectControl();
return resultvalue;
}