2018-03-05 03:35 PM
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 #potentiometer2018-03-05 05:32 PM
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)
2018-03-06 02:57 AM
Hi,
thanks for answer.
Unfortunately i dont have scope or logic analyser...
About the port., i guess the CubeMX set up the
, and i only set the slave select pin.The program compiles normally.
2018-03-06 05:01 AM
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.
2018-03-06 09:06 AM
I slow down the SPI Baud Rate at 3 bits/sec and i attach the led... nothing flashed.
the registers (as i can see) are all empty
https://i.gyazo.com/fd1e0309f221d0e372b051d1afb1419c.png
so, i guess i have made wrong the setup??
2018-03-06 10:47 AM
Compare those 0s with the values you would have expected and see if they match.
Your code showed no initialization so you may want to look into that first.
2018-03-07 09:20 AM
did you fix these faulty lines ?
HAL_GPIO_WritePin(CS, GPIO_PIN_RESET);
HAL_GPIO_WritePin(CS, GPIO_PIN_SET);
2018-03-07 09:38 AM
for the setup i use the CubeMX... i don't know if there is a mistake
2018-03-07 10:09 AM
'
i don't know if there is a mistake'
easy: take out the datasheet and ask yourself what values the registers should have. and then figure out why they don't have those values you were expecting.