2018-12-17 10:46 PM
Hi, I'm new to this environment. I try never to ask questions on forums but I've been stuck for over a week. I set up a blue pill board and tried a simple SPI setup of a single 74HC595 and a single 74HC165. I got the 595 working great with this code.
message = 8;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, false);
HAL_Delay(100);
HAL_SPI_Transmit(&hspi1, (uint8_t *)message, 1, HAL_MAX_DELAY);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, true);
HAL_Delay(1000);
This can be used to switch any of the pins on the 595. I assumed the following code would read the input.
uint8_t receive;
while(true)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, false);
HAL_Delay(100);
HAL_SPI_Receive(&hspi1, receive, 1, HAL_MAX_DELAY);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, true);
HAL_Delay(1000);
Debug_Print(receive);
}
But no luck. If i scope the the sclk pin it doesn't even send the clock pulses. another interesting thing is that if i include this receive code and the transmit code. the transmit code stops working?
here is my SPI setup
static void MX_SPI1_Init(void)
{
__HAL_RCC_SPI1_CLK_ENABLE();
/* SPI1 parameter configuration*/
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_1EDGE;
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 = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
Thanks in advance, I don't have a forum home for this ide yet. This is me looking for one.