STM32F411 DAC MCP4822 SCK MOSI pins not working

Post here first, or if you can't find a relevant section!
Post Reply
justinjools
Posts: 41
Joined: Thu May 02, 2024 11:10 am

STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by justinjools »

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
Attachments
STM32_pinout_MOSI_SCK.jpg
STM32_pinout_MOSI_SCK.jpg (79.17 KiB) Viewed 4924 times
STM32ardui
Posts: 142
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by STM32ardui »

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()?
justinjools
Posts: 41
Joined: Thu May 02, 2024 11:10 am

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by justinjools »

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
STM32ardui
Posts: 142
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by STM32ardui »

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
You have been told, that there a 2 options:
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().
justinjools
Posts: 41
Joined: Thu May 02, 2024 11:10 am

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by justinjools »

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.
STM32ardui
Posts: 142
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by STM32ardui »

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.
May be you should re-read your own posting from yesterday evening?
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
And you want to use PB15 as MOSI2.

So goodbye and good luck!
justinjools
Posts: 41
Joined: Thu May 02, 2024 11:10 am

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by justinjools »

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.
justinjools
Posts: 41
Joined: Thu May 02, 2024 11:10 am

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by justinjools »

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() {
}
Last edited by justinjools on Fri Jul 26, 2024 1:25 pm, edited 2 times in total.
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: STM32F411 DAC MCP4822 SCK MOSI pins not working

Post by fpiSTM »

Next time post your full code....
Post Reply

Return to “General discussion”