Introduction to K210-bare metal development (9) IIS power amplifier speaker small speaker (SD card + fat file system) _ only wav format (wav decoder used)

Development board: K210 AIRV R3 version widora

Development environment: kendryte IDE official

Required reference documents: Standalone SDK Programming Guide v0.5.0, and Widora schematic

(1) Create a new folder 10my_code_tfcard_music

Gift + earth

Example Search for music, select the development version (develop) and download it to the newly created folder

Installation dependencies

Clean + build

I reported an error here

It shows undefined, should it be the pot of my previous SD/TF card chapter?

 

SPI0 is used (the SD card used in the previous section is SPI0) So we can add the macro definition ourselves.

Reinstall the dependencies once (I am used to this), then clean + build

This is useless. After looking at it, it turned out to be the pot for installing dependencies. Don't reinstall dependencies, just clean + build.

After setting up the environment, start to change the code

(2) Modify the code

Bind the pins of the TF card first

Save the following SD card to get the pins

Don't care about the purple area, just look at dmac_init and so on. Now let’s see if the SD card needs to be changed.

Go to see, click sdcard_test() and press F12 to jump

Sdinit is useful in it

These are not used, you can delete them, and I set the frequency for SPI to 30M, and I can start the test here, and I ran 10M before (if you can’t reduce the speed by yourself)

Let’s see if the SD card is successfully read.

Reported an error

Just delete the 3 functions, double-click to enter, and delete

Go one-stop

The SD card cannot be read. Could it be that the speed is too fast, try changing it back to 20M

It is true that SPI is too big, I changed it to 20M and I am OK (because the CPU ran 800M/2=400M before, this time it ran 320M/2 = 160M)

Sysctl_pll_set_freq(SYSCTL_PLL0, 320000000UL) in main.c; This function indicates that it is running 160M or 320M?

SD card + fat file system transplantation is no problem, let's take a look at I2S audio

 

(3) Look at I2S (audio protocol) directly below

Schematic diagram 

I2S_WS -> IO33

I2S_DO -> IO34

I2S_BCK-> IO35

Go to config ->device and bind the pins, remember to save

Let's take a look at the code I2S in Chapter 17

Look at dmac. There is nothing good about DMA, in Chapter 14.

Just use it directly, don’t worry about what is done inside, it will write it for us

main.c has been tested just now, it's useless, comment it out

Look directly at wav_test

Take a look at this initialization, after reading it, it should be the initialization of the player. Don’t worry.

A DMA interrupt is used here, wait to see what the interrupt executes in it

i2s_init() is the I2S used

i2s_init(I2S_DEVICE_0, I2S_TRANSMITTER, 0x03);

Corresponding to IIS0, sending mode, channel mask is 3 (what does the manual do not have)

carry on 

i2s_tx_channel_config(

I2S_DEVICE_0, I2S_CHANNEL_0, RESOLUTION_16_BIT, SCLK_CYCLES_32,

/*TRIGGER_LEVEL_1*/ TRIGGER_LEVEL_4, RIGHT_JUSTIFYING_MODE);

Corresponding to I2S0, channel 0, sending digits 16 bits, clock selection 32 bits (the clock configured by I2S), DMA depth 4, right justified

Don't care about the initial wav audio decoder

Start singing

i2s_play(I2S_DEVICE_0, DMAC_CHANNEL3, (void *)wav_file.buff_current,

wav_file.buff_current_len, wav_file.buff_current_len, 16, 2);

Corresponding to I2S0, channel 3 used by the decoder (if there is a DMA interrupt, please see later), the stored song buffer,

The length of the buffer, the number of frames sent in a single time (should be 256*1024), the single sampling bit width is 16, 2 channels

Start decoding, then jump out of the infinite loop

Look at DMA interrupt

Obviously, it is the state machine form used to judge whether to finish playing or continue playing through DMA.

My SD card only has 2 songs, try beyong's songs, I don’t know if mp3 can be played with wav

Try one-stop

 

The playback is rustling, it should not be able to play, I will search for songs in wav format

printf("result:%d\n", status);

if(BG_READ_WORD(index) != RIFF_ID)

return UNVALID_RIFF_ID;

The result 3 is returned, which is an invalid ID, it should be mp3 not working

I made a qiao.wav on the U disk to try

Try one more stop

It succeeded. I can hear the sound after connecting the speaker. The 8 ohm 2W speaker I use here is very quiet

Widola’s speakers are connected here

NS4168 for power amplifier

Sure enough, I can't bring my 8 Euro 2W

It is recommended that you use 4 ohms 2W and below

 

The code is too big, still post the link, there is the first test qiao.wav, so the file is a bit big

 

Link: https://pan.baidu.com/s/1bP-I8wC5QoDdkfzM6XL1pA 
Extraction code: 5qn9 After
copying this content, open Baidu Netdisk  mobile phone App, the operation is more convenient

 

 

 

Guess you like

Origin blog.csdn.net/jwdeng1995/article/details/108087083