cancel
Showing results for 
Search instead for 
Did you mean: 

Bit-banged I2S on STM32F103

PGild.1
Associate III

Hello everybody,

I am trying to bit-bang an I2S interface on an STM32F103 at 72MHz using TIM2.

Am I way too optimistic to get a 3MHz "clock" out on a pin? The fastest I can seem to get it is at 90kHz.

I have set the "prescaler" of TIM2 to "0" and "1".

And, I have set the auto reload register at 11 with an interrupt writing "0" and "1" to a GPIO pin.

And Channel 1 set as "Output comapre no output" as well as "PWM1 output" on PA15.

The CPU and timer frequencies are 72MHz.

Any suggestions? (other than get an STM32 with I2S ;) )

Kind regards,

pieterg!

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

Well, there are some users who torture themselves with the emulation of I2S. However, it should be possible to emulate I2S with the STM32F103 as well, as a search with your favourite search engine for e.g. "+I2S +emulation +STM32" will reveal.

Among other things, you should then also find the AN5086, which deals with the topic and implements it with SPI and a timer on a Cortex-M0 (STM32L0).

There is also a bare-metal idea with an STM32F1 here.

Maybe that will help you?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
Peter BENSCH
ST Employee

Well, there are some users who torture themselves with the emulation of I2S. However, it should be possible to emulate I2S with the STM32F103 as well, as a search with your favourite search engine for e.g. "+I2S +emulation +STM32" will reveal.

Among other things, you should then also find the AN5086, which deals with the topic and implements it with SPI and a timer on a Cortex-M0 (STM32L0).

There is also a bare-metal idea with an STM32F1 here.

Maybe that will help you?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello Peter,

Thank you so much for the quick response!

I have followed the application and the logic analyser results looks very promising.

I see a 2.286MHz clock now (as expected for the CubeMX settings) and I have the "WS" signal from a timer as per the application note.

Kind Regards,

pieterg!

Great!

When the problem will be solved, please mark this thread as answered by selecting Select as best, as also explained here. This will help other users find that answer faster.

Good luck!

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello Peter,

I am still struggling with this.

I have read the application note, but the section of the TIM settings "confuses' me. And I am sure my configuration is wrong, but where?

In CubeMX my "TIM2" settings are:

Trigger Source: ETR1 (connectedt tp SPI-SCK)

Clock Source: Internal Clock (is this APB1 or APB2 timer clock?)

Channel 3: "Output Compare CH3"

Then "Counter Settings":

Counter Period: 31 -> as per application note

auto-reload preload: Enable

Then Output Compare Channel 3:

Mode: <not sure what this must be. I have tried "all" of them>

Pulse: 15 -> as per application note

Output compare preload: Enable

CH Polarity: High

I have set my SPI2 as follows:

Data size 16 bits

prescaler 256 for 125kbps baudrate

Thank you so much in advance.

pieterg!