Hello Everyone,
I am using PIXY 2 to interface with STM32F7 using SPI with SS.
I am following this request response given in this link
https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide
I have few things which i need to understand regarding pixy2.
-
While receiving version from pixy2 i noticed that it sends first 9 bytes as garbage. Is that suppose to be normal? I checked this thing for other cases like Toggling lamp and encountered with the same issue.
-
While trying to read blocks from pixy i get following kind of data which is not supposed to be.
REQUEST:
uint8_t getBlocks[] = {
0xae,
0xc1,
32,
2,
7,
2
};
Response in decimal:
175 193 33 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
Have i missed something while initializing???
I can perfectly read the version and toggle the lamp. But i can’t read the blocks. Using pixyMon i have set the signature 1(RED).
Here is the code for version and its response:
uint8_t versionRequest[] =
{
0xae, // first byte of no_checksum_sync (little endian -> least-significant byte first)
0xc1, // second byte of no_checksum_sync
0x0e, // this is the version request type
0x00, // data_length is 0
};
CS_Low;
HAL_SPI_Transmit(&hspi1, versionRequest, 4, 1000);
HAL_Delay(1);
HAL_SPI_Receive(&hspi1, dataReceived, 9, 1000); //first 9 garbage data
HAL_SPI_Receive(&hspi1, dataReceived, 22, 1000);
HAL_UART_Transmit(&huart3, (uint8_t*)"DATA RECEIVED: \r\n", strlen("DATA RECEIVED: \r\n"), 1000);
for (int i = 0; i < 22; i++) {
if (i < 12)
sprintf((char*)printBuff, "%d ", dataReceived[i]);
else
sprintf((char*)printBuff, "%c", dataReceived[i]);
HAL_UART_Transmit(&huart3, printBuff, strlen((char*)printBuff), 1000);
}
HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n\r\n", strlen("\r\n\r\n"), 1000);
CS_High;
for (int i = 0; i < 26; i++)
dataReceived[i] = 0;
HAL_Delay(1000);
RESPONSE FOR VERSION REQUEST:
175 193 15 16 14 3 0 34 3 0 11 0 general
CODE FOR GET BLOCKS:
uint8_t getBlocks[] = {
0xae,
0xc1,
32,
2,
7,
2
};
CS_Low;
HAL_SPI_Transmit(&hspi1, getBlocks, 5, 1000);
HAL_Delay(1);
HAL_SPI_Receive(&hspi1, dataReceived, 9, 1000); //garbage values
HAL_SPI_Receive(&hspi1, dataReceived, 18, 1000);
HAL_UART_Transmit(&huart3, (uint8_t*)"DATA RECEIVED: \r\n", strlen("DATA RECEIVED: \r\n"), 1000);
for (int i = 0; i < 18; i++) {
sprintf((char*)printBuff, "%d ", dataReceived[i]);
HAL_UART_Transmit(&huart3, printBuff, strlen((char*)printBuff), 1000);
}
HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n\r\n", strlen("\r\n\r\n"), 1000);
CS_High;
for (int i = 0; i < 26; i++)
dataReceived[i] = 0;
HAL_Delay(1000);
RESPONSE FOR GET BLOCKS:
175 193 33 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
I am using SPI at around 1.7 MHz But i have tried increasing the speed and the result is same.
I am using CPOL = 0 and CPHA = 2nd EDGE 1.
I have tried using Mode 3 i.e CPOL = 1 and CPHA = 1. But it results the same.
Datasize of SPI is 8 bit and First bit is MSB
Here is the initialization of SPI for STM32F7 using HAL
void MX_SPI1_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
What i am doing wrong while trying to getBlocks from pixy2
Any suggestions will be appreciated.