STM32F411 DAC MCP4822 SCK MOSI pins not working
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
STM32F411 DAC MCP4822 SCK MOSI pins not working
Hi,
I have STM32F103 blue working with MCP4822 DAC using SCK MOSI pins as below. When I try STM32F411 black using the same code and pins on I get no output. I have checked the pinouts and these pins are the same for STM32F103 and STM32F411. I am using standard STM32Duino core https://github.com/stm32duino
Do you have any idea what this is?
SCK A5
MOSI A7
CS_PIN PB1
I have STM32F103 blue working with MCP4822 DAC using SCK MOSI pins as below. When I try STM32F411 black using the same code and pins on I get no output. I have checked the pinouts and these pins are the same for STM32F103 and STM32F411. I am using standard STM32Duino core https://github.com/stm32duino
Do you have any idea what this is?
SCK A5
MOSI A7
CS_PIN PB1
- Attachments
-
- STM32_pinout_MOSI_SCK.jpg (79.17 KiB) Viewed 4924 times
-
- Posts: 142
- Joined: Mon May 06, 2024 1:46 pm
- Location: Germany
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
Do you choose "Generic STM32F4" and board part number "Blackpill 411CE" in Arduino IDE?
PA7 MOSI
PA5 CLK
PA4 CS
PB12 CS2 should be correct for a Blackpill from WeActStudio as default pins
So you ever take a look into the variant.h files???
Or do you use SPI.setSSEL()?
PA7 MOSI
PA5 CLK
PA4 CS
PB12 CS2 should be correct for a Blackpill from WeActStudio as default pins
So you ever take a look into the variant.h files???
Or do you use SPI.setSSEL()?
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
I have been using Generic STM32F4 / Generic F411CEUx rather than Blackpill F411CE so will give that a go.
I have been looking at STM32 API for SPI because I want to set up using two SPI buses when I get the SPI working, as below.
// SPI1
SPI.setMOSI(PB15); // MOSI2
SPI.setMISO(PB14); // MISO2
SPI.setSCLK(PB13); // SCK2-4
But what does SPI.setSSEL() do?
I looked it up what it said: "Using setSSEL() allows to enable hardware CS pin management linked to the SPI peripheral."
I'm not sure what this and there is not an example on the Wiki github page.
https://github.com/stm32duino/Arduino_C ... ki/API#spi
I have been looking at STM32 API for SPI because I want to set up using two SPI buses when I get the SPI working, as below.
// SPI1
SPI.setMOSI(PB15); // MOSI2
SPI.setMISO(PB14); // MISO2
SPI.setSCLK(PB13); // SCK2-4
But what does SPI.setSSEL() do?
I looked it up what it said: "Using setSSEL() allows to enable hardware CS pin management linked to the SPI peripheral."
I'm not sure what this and there is not an example on the Wiki github page.
https://github.com/stm32duino/Arduino_C ... ki/API#spi
-
- Posts: 142
- Joined: Mon May 06, 2024 1:46 pm
- Location: Germany
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
You have been told, that there a 2 options:justinjools wrote: Thu Jul 11, 2024 9:51 pm I have been looking at STM32 API for SPI because I want to set up using two SPI buses when I get the SPI working, as below.
Code: Select all
// SPI1 SPI.setMOSI(PB15); // MOSI2 SPI.setMISO(PB14); // MISO2 SPI.setSCLK(PB13); // SCK2-4
1. Using 1 SPI interface with different CS-pins
2. Using 2 SPI-interfaces. Then you have to define a second SPI object and it must have a different name like "SPI2".
The rest depends on the libraries you are using.
If there is a method that have CS-pin as parameter you don't need SPI.setSSEL().
And: before you can use a SPI.beginTransaction() in your code, you have to initialise with SPI.begin().
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
I re-did the circuit on another breadboard and after much wiggling and Arduino IDE settings it came to life. I don't know what was wrong. Sometimes things take a lot of re-doing and wiggling 
But just to state it works the same as STM32 blue with.
PA7 MOSI
PA5 CLK
@STM32ardui
You are confused sir, this post is not regarding using 2x SPI rather getting STM32F411 with DAC. Please reply to correct post.

But just to state it works the same as STM32 blue with.
PA7 MOSI
PA5 CLK
@STM32ardui
You are confused sir, this post is not regarding using 2x SPI rather getting STM32F411 with DAC. Please reply to correct post.
-
- Posts: 142
- Joined: Mon May 06, 2024 1:46 pm
- Location: Germany
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
May be you should re-read your own posting from yesterday evening?justinjools wrote: Fri Jul 12, 2024 4:18 pm @STM32ardui
You are confused sir, this post is not regarding using 2x SPI rather getting STM32F411 with DAC.
And you want to use PB15 as MOSI2.justinjools wrote: Thu Jul 11, 2024 9:51 pm I have been looking at STM32 API for SPI because I want to set up using two SPI buses when I get the SPI working, as below.
Code: Select all
// SPI1 SPI.setMOSI(PB15); // MOSI2 SPI.setMISO(PB14); // MISO2 SPI.setSCLK(PB13); // SCK2-4
So goodbye and good luck!
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
Yes, that is a different post. I was replying to the person who commented. Oh well! (and maybe you should learn some politeness and empathy)
I discovered something very strange, the opamp is working but at a low level. I accidentally connected the 3v3 pin to GND and it amplifies the signal as it seems it should be.
I discovered something very strange, the opamp is working but at a low level. I accidentally connected the 3v3 pin to GND and it amplifies the signal as it seems it should be.
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
Jeez, this drove me crazy searching for an answer for over a week posting on forums incl. here. I finally find out you need to put settings in Setup - why don't they tell you this!
#include <SPI.h>
#define CS_PIN PB0 //Chip Select or Slave Select Pin
void setup() {
// Initialising the SPI connection on default port
// SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0)); //MSB first, according to the DAC spec
SPI.setMOSI(PB15); // PB5 // PA7
SPI.setMISO(PB14); // PB4 // PA6
SPI.setSCLK(PB13); // PB3 // PA5
}
void loop() {
}
#include <SPI.h>
#define CS_PIN PB0 //Chip Select or Slave Select Pin
void setup() {
// Initialising the SPI connection on default port
// SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0)); //MSB first, according to the DAC spec
SPI.setMOSI(PB15); // PB5 // PA7
SPI.setMISO(PB14); // PB4 // PA6
SPI.setSCLK(PB13); // PB3 // PA5
}
void loop() {
}
Last edited by justinjools on Fri Jul 26, 2024 1:25 pm, edited 2 times in total.
Re: STM32F411 DAC MCP4822 SCK MOSI pins not working
Next time post your full code....