cancel
Showing results for 
Search instead for 
Did you mean: 

How to use STM32F401 mcu to driver color sensor.

Hfeix.1
Associate

Hi, all.

I hope anyone who can help me ~

I now use STM32F401 & CubeMx to driver color sensor, the color sensor's timing requirements like this:0693W00000GXKblQAH.pngI use master/slave Time to do this:

master Tim1' CH1 to seed PWM(cycle is 500ns, high 200ns, low 300ns), and Tim1 also use for DMA to get data from Dout port(DMA cycle is 500ns too). And use slave Tim3 to control Tim1 to send 12 pulses at sample time. every 12 pulses finished, stop tim1&tim3, wait t2(4us)time, then start again.

According to the above logic, I got this wave:

0693W00000GXKmeQAH.jpgFrom this picture, I unable to get 12 pulses stably(sometimes 12 times, sometimes 14 times and sometimes 10times).

Thanks for everyone again.

2 REPLIES 2
TDK
Guru

You can use a timer in gated slave mode being driven by a master timer to generate the CK signal. If you set up a slave SPI and use that as the clock and use Dout as MOSI, you can clock in the Dout data using DMA.

If you feel a post has answered your question, please click "Accept as Solution".

hi,

Thanks for your reply, I solved it by using register to do master/slave time(not use HAL).