Very simple test for SOMO-14D Embedded Audio-Sound Module

Dependencies:   mbed

Committer:
lnadal
Date:
Sun Oct 10 07:40:59 2010 +0000
Revision:
0:78e5168d3809

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lnadal 0:78e5168d3809 1 #include "mbed.h"
lnadal 0:78e5168d3809 2
lnadal 0:78e5168d3809 3 /* Simple test for SOMO-14D module.
lnadal 0:78e5168d3809 4 Plays a selected file. See www.4dsystems .com.au for details.
lnadal 0:78e5168d3809 5
lnadal 0:78e5168d3809 6 Author: Lluis Nadal.
lnadal 0:78e5168d3809 7 Date: October 10th 2010.
lnadal 0:78e5168d3809 8
lnadal 0:78e5168d3809 9 File names must match file number in decimal: 0000.ad4 ... to 0511.ad4
lnadal 0:78e5168d3809 10 Commands:
lnadal 0:78e5168d3809 11 File addres (fileNumber): 0x0000 - 0x01FF
lnadal 0:78e5168d3809 12 Play/Pause: 0xFFFE
lnadal 0:78e5168d3809 13 Volume (8 levels): 0xFFF0 - 0xFFF7
lnadal 0:78e5168d3809 14 Stop: 0xFFFF
lnadal 0:78e5168d3809 15
lnadal 0:78e5168d3809 16 */
lnadal 0:78e5168d3809 17
lnadal 0:78e5168d3809 18 DigitalOut reset(p16); // connected to SOMO p10
lnadal 0:78e5168d3809 19 DigitalIn busy(p15); // connected to SOMO p5
lnadal 0:78e5168d3809 20
lnadal 0:78e5168d3809 21 // SOMO p9 connected to ground
lnadal 0:78e5168d3809 22 // SOMO p8 connected to Vcc = +3.3V
lnadal 0:78e5168d3809 23 // SOMO p11, p12 connected to speaker
lnadal 0:78e5168d3809 24 DigitalOut data(p5); // connected to SOMO p4
lnadal 0:78e5168d3809 25 DigitalOut clk(p7); // connected to SOMO p3
lnadal 0:78e5168d3809 26 unsigned short fileNumber;
lnadal 0:78e5168d3809 27 unsigned short command;
lnadal 0:78e5168d3809 28
lnadal 0:78e5168d3809 29
lnadal 0:78e5168d3809 30 void init() {
lnadal 0:78e5168d3809 31
lnadal 0:78e5168d3809 32 clk = 1;
lnadal 0:78e5168d3809 33 reset = 1;
lnadal 0:78e5168d3809 34 reset = 0;
lnadal 0:78e5168d3809 35 wait(0.005);
lnadal 0:78e5168d3809 36 reset = 1;
lnadal 0:78e5168d3809 37 wait(0.3);
lnadal 0:78e5168d3809 38 }
lnadal 0:78e5168d3809 39
lnadal 0:78e5168d3809 40
lnadal 0:78e5168d3809 41
lnadal 0:78e5168d3809 42 void writeData(unsigned short value) {
lnadal 0:78e5168d3809 43
lnadal 0:78e5168d3809 44 clk = 0;
lnadal 0:78e5168d3809 45 wait(0.002);
lnadal 0:78e5168d3809 46 for (int i = 0; i<16; i++) {
lnadal 0:78e5168d3809 47 wait(0.000100f);
lnadal 0:78e5168d3809 48 data = value & 0x8000; // selects most significant bit
lnadal 0:78e5168d3809 49 wait(0.000001f);
lnadal 0:78e5168d3809 50 clk = 1;
lnadal 0:78e5168d3809 51 wait(0.000050f);
lnadal 0:78e5168d3809 52 clk=0;
lnadal 0:78e5168d3809 53 value = value <<1; // shifts one bit left
lnadal 0:78e5168d3809 54 }
lnadal 0:78e5168d3809 55 clk =1;
lnadal 0:78e5168d3809 56 wait(0.002);
lnadal 0:78e5168d3809 57 }
lnadal 0:78e5168d3809 58
lnadal 0:78e5168d3809 59
lnadal 0:78e5168d3809 60 int main() {
lnadal 0:78e5168d3809 61 wait(0.5);
lnadal 0:78e5168d3809 62 while (busy == 1); // checks if SOMO is busy
lnadal 0:78e5168d3809 63
lnadal 0:78e5168d3809 64 fileNumber = 0x0001; //selects 2nd file
lnadal 0:78e5168d3809 65 command = 0xFFFE; // play file command
lnadal 0:78e5168d3809 66
lnadal 0:78e5168d3809 67 init();
lnadal 0:78e5168d3809 68
lnadal 0:78e5168d3809 69 writeData(fileNumber);
lnadal 0:78e5168d3809 70 writeData(command);
lnadal 0:78e5168d3809 71
lnadal 0:78e5168d3809 72 }