SPI potentiometer don't work (CubeMX & Nucleo103)
Hi,
Maybe i have a stupid question or mistake but i am searching and i can't make it work, so if you can help please.
First i created a new project at CubeMX integrated in Atollic TrueStudio 8.0.
I enable the SPI2 as Full Duplex Master and the Hardware NSS disabled, and the PB1 as output for the Chip Select (CS).
I generated the code without change the configuration at SPI and i add the follow lines (my last of many tries) at the main.c
&sharpdefine CS GPIOB, GPIO_PIN_1main(void){
HAL_GPIO_WritePin(CS, GPIO_PIN_SET);
while(1){
for(int i=0;i<128; i++){
HAL_GPIO_WritePin(CS, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi2, 0x00, size, 0xFF); HAL_SPI_Transmit(&hspi2, 0x4, size, 0xFF); HAL_GPIO_WritePin(CS, GPIO_PIN_SET); HAL_Delay(10); }for(int j=128;j>0; j++){
HAL_GPIO_WritePin(CS, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi2, 0x00, size, 0xFF); HAL_SPI_Transmit(&hspi2, 0x8, size, 0xFF); HAL_GPIO_WritePin(CS, GPIO_PIN_SET); HAL_Delay(10); }for(int o=0;o<128; o++){
HAL_GPIO_WritePin(CS, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi2, 0x01, size, 0xFF); HAL_SPI_Transmit(&hspi2, 0x20, size, 0xFF); HAL_GPIO_WritePin(CS, GPIO_PIN_SET); HAL_Delay(10); }for(int k=128;k>0; k++){
HAL_GPIO_WritePin(CS, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi2, 0x01, size, 0xFF); HAL_SPI_Transmit(&hspi2, 0x24, size, 0xFF); HAL_GPIO_WritePin(CS, GPIO_PIN_SET); HAL_Delay(10); }}
}
Of course, i write here only the code i add. The pre-generated code remains as is (
and more).At the hardware part now, i used a common MCP4231 with the following connection:
1 -> PB1, 2 ->PB13, 3-> PB15, 4,5,10 -> GND, 6,9-> LED with series resistor 220 Ohm, 7,8,14 -> 5V
I left the MISO float, because there is nothing to receive.
I check the connections many times but nothing happens.
Maybe i missed information, but anything needed i can add after.
Any ideas how it works? Thank you very much!!!
#spi #potentiometer