Skip to main content
ioannis
Associate
March 5, 2018
Question

SPI potentiometer don't work (CubeMX & Nucleo103)

  • March 5, 2018
  • 8 replies
  • 1918 views
Posted on March 06, 2018 at 00:35

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_1

main(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 (

http://prntscr.com/incfqx

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
This topic has been closed for replies.

8 replies

T J
Senior III
March 6, 2018
Posted on March 06, 2018 at 02:32

You forgot the 'Port'

    HAL_GPIO_WritePin(E144_M0_GPIO_Port, E144_M0_Pin, GPIO_PIN_SET);

do you have a scope ?  you can see the pin is not working.

it shouldn't compile, i thought ??

(never liked Atollic)

ioannis
ioannisAuthor
Associate
March 6, 2018
Posted on March 06, 2018 at 10:57

Hi,

thanks for answer.

Unfortunately i dont have scope or logic analyser...

About the port., i guess the CubeMX set up the

https://prnt.sc/inifbu

, and i only set the slave select pin.

The program compiles normally.

henry.dick
Associate II
March 6, 2018
Posted on March 06, 2018 at 13:01

Tough to debug without a scope or logic analyzer but not impossible.

If you have a debugger, try to get a shot of the set up of the registers, compare them to the data sheet to see if they are as expected.

If you have UART, send the data out so you can check on the computer.

If you have a frequency meter - many multimeters do, out it on the sclk ot mosi line to make sure that there is some activity.

Anything fails, put an led on the sclk or mosi and see if the led blinks - you will need to slow down the transmission. 

....

So if you look around there must be things around you that can help.

T J
Senior III
March 7, 2018
Posted on March 07, 2018 at 18:20

did you fix these faulty lines ?

HAL_GPIO_WritePin(CS, GPIO_PIN_RESET);

HAL_GPIO_WritePin(CS, GPIO_PIN_SET);