Announcement

Collapse
No announcement yet.

Somo-II using ATxmega128A1

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Somo-II using ATxmega128A1

    Hi,

    I am trying to use SOMO-II in a project using ATxmega128A1 (Microchip-Atmel).
    The compiler used is the CodeVisionAVR V3.33 standard Ansi C.
    I tested the SOMO-II in the key mode to assure that the micro-SD was OK and it play well.
    The micro-SD is Kingston 2GB FAT16 and there are tracks named 001.mp3,002.mp3,... in a folder 01.

    Below there are chunks of the program for Somo-II in serial mode.
    Somo-II do not work in serial mode with this program. The led never light. I do not know what I am doing wrong.

    Any help and suggestions are welcome. Thank you!


    //___________________________________ usarts_init.h ___________________________________________________________________

    #ifndef _USARTS_INIT_INCLUDED_
    #define _USARTS_INIT_INCLUDED_

    // USARTC0 is used as the default input device by the 'getchar' function
    // #define _ALTERNATE_GETCHAR_ is inserted for this purpose
    // in the main program source file before #include <stdio.h>
    char getchar(void);
    // USARTC0 is used as the default output device by the 'putchar' function
    // #define _ALTERNATE_PUTCHAR_ is inserted for this purpose
    // in the main program source file before #include <stdio.h>
    void putchar(char c);
    // USARTC0 initialization
    void usartc0_init(void);

    #endif


    //____________________________________ usarts_init.c __________________________________________________________________

    // I/O Registers definitions
    #include <xmega128a1.h>

    // USARTs initialization functions
    #include "usarts_init.h"

    // USARTC0 initialization
    void usartc0_init(void)
    {
    // Note: The correct PORTC direction for the RxD, TxD and XCK signals
    // is configured in the ports_init function.

    // Transmitter is enabled
    // Set TxD=1
    PORTC.OUTSET=0x08;

    // Communication mode: Asynchronous USART
    // Data bits: 8
    // Stop bits: 1
    // Parity: Disabled
    USARTC0.CTRLC=USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc;

    // Receive complete interrupt: Disabled
    // Transmit complete interrupt: Disabled
    // Data register empty interrupt: Disabled
    USARTC0.CTRLA=(USARTC0.CTRLA & (~(USART_RXCINTLVL_gm | USART_TXCINTLVL_gm | USART_DREINTLVL_gm))) |
    USART_RXCINTLVL_OFF_gc | USART_TXCINTLVL_OFF_gc | USART_DREINTLVL_OFF_gc;

    // Required Baud rate: 9600
    // Real Baud Rate: 9601,0 (x1 Mode), Error: 0,0 %
    USARTC0.BAUDCTRLA=0xF5;
    USARTC0.BAUDCTRLB=((0x0C << USART_BSCALE_gp) & USART_BSCALE_gm) | 0x0C;

    // Receiver: On
    // Transmitter: On
    // Double transmission speed mode: Off
    // Multi-processor communication mode: Off
    USARTC0.CTRLB=(USARTC0.CTRLB & (~(USART_RXEN_bm | USART_TXEN_bm | USART_CLK2X_bm | USART_MPCM_bm | USART_TXB8_bm))) |
    USART_RXEN_bm | USART_TXEN_bm;
    }

    // Receive a character from USARTC0
    // USARTC0 is used as the default input device by the 'getchar' function
    // #define _ALTERNATE_GETCHAR_ is inserted for this purpose
    // in the main program source file before #include <stdio.h>
    #pragma used+
    char getchar(void)
    {
    char data;
    unsigned char status;

    while (1)
    {
    while (((status=USARTC0.STATUS) & USART_RXCIF_bm) == 0);
    data=USARTC0.DATA;
    if ((status & (USART_FERR_bm | USART_PERR_bm | USART_BUFOVF_bm)) == 0) return data;
    }
    }
    #pragma used-

    // Write a character to the USARTC0 Transmitter
    // USARTC0 is used as the default output device by the 'putchar' function
    // #define _ALTERNATE_PUTCHAR_ is inserted for this purpose
    // in the main program source file before #include <stdio.h>
    #pragma used+
    void putchar(char c)
    {
    while ((USARTC0.STATUS & USART_DREIF_bm) == 0);
    USARTC0.DATA=c;
    }
    #pragma used-

    //____________________________________________________________________________________________________ _________________
    .
    .
    .
    void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2);
    .
    .
    .
    somo_cmd(0x0F,0x00,0x01,0x01); // Play specifing folder (01) and track (01)
    .
    .
    .
    //____________________________________________________________________________________________________ _________________

    void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2)
    {
    unsigned int chk;
    unsigned char chk1;
    unsigned char chk2;

    chk = 0xFFFF - ((unsigned int)cmd + (unsigned int)feedback + (unsigned int)para1 + (unsigned int)para2) + 0x0001;
    chk1 = (unsigned char)(chk >> 8);
    chk2 = (unsigned char)chk;

    putchar(0x7E);
    putchar(cmd);
    putchar(feedback);
    putchar(para1);
    putchar(para2);
    putchar(chk1);
    putchar(chk2);
    putchar(0xEF);

    delay_ms(100);
    }

    //____________________________________________________________________________________________________ _________________
    Last edited by Pardini; 7th October 2018, 06:53 AM.

  • #2
    Hello Pardini,

    Welcome to the forum. Looking at the code you've posted, it seems that you got everything needed to command the SOMO-II module.
    I could suggest checking first the serial UART output of the ATxmega to check if the command sent are correct.
    You can also check the SOMO-II serial commands by sending the commands directly using a serial terminal.
    For additional reference on the functions, you can check out the SOMO-II library created for our IoD modules (Written in C++)
    https://github.com/4dsystems/SOMOIoD...rc/SOMOIod.cpp

    Best Regards,

    Comment


    • #3
      Hello Jerson,

      Thank you for the reply. After some testing and using "SOMO II Demo" (good tool) I can say that:

      1. There are no problems with the program and the serial communication is OK.
      2. The problem is with the micro-SD. I used the "primary method" with the correct naming of the tracks (001.mp3,...) in a folder named 01. With some micro-SD this do not work and in this cases the "SOMO II Demo" shows that SOMO-II resets continuously (see attached). I tried reformatting the micro-SD with the same result.
      3. I changed the micro-SD, remake the 01 folder and all work perfectly with my program and with "SOMO-II Demo" (see attached).
      4. I tested also with the "secondary method" (without the folder) all works perfectly with my program and with "SOMO-II Demo" (see attached).

      What happens with some micro-SD? in my case the micro-SD are Kingston 2GB.

      If this can help someone, below there is the working program:

      //____________________________________________________________________________________________________ _________________
      .
      .
      .
      unsigned char getpin(unsigned char *door);
      void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2);
      .
      .
      .
      #define ad_aeternum while(1)
      #define play_next somo_cmd(0x01,0x00,0x00,0x00)
      #define play_previous somo_cmd(0x02,0x00,0x00,0x00)
      #define play_track(track) somo_cmd(0x03,0x00,0x00,track)
      #define increase_volume somo_cmd(0x04,0x00,0x00,0x00)
      #define decrease_volume somo_cmd(0x05,0x00,0x00,0x00)
      #define set_volume(vol) somo_cmd(0x06,0x00,0x00,vol)
      #define specify_EQ(eq) somo_cmd(0x07,0x00,0x00,eq)
      #define repeat_track(track) somo_cmd(0x08,0x00,0x00,track)
      #define play_source(usb_sd) somo_cmd(0x09,0x00,0x00,usb_sd)
      #define sleep_somo somo_cmd(0x0A,0x00,0x00,0x00)
      #define reset_somo somo_cmd(0x0C,0x00,0x00,0x00)
      #define play_selected somo_cmd(0x0D,0x00,0x00,0x00)
      #define pause_play somo_cmd(0x0E,0x00,0x00,0x00)
      #define play_folder_track(folder,track) somo_cmd(0x0F,0x00,folder,track)
      #define play_continuous somo_cmd(0x11,0x00,0x00,0x01)
      #define stop_playing somo_cmd(0x16,0x00,0x00,0x00)
      #define play_random somo_cmd(0x18,0x00,0x00,0x00)
      #define repeat_current somo_cmd(0x19,0x00,0x00,0x00)
      #define single_play somo_cmd(0x19,0x00,0x00,0x01)
      #define wait_end_of_play n=0;while(n==0)n=getpin("B5") // Busy pin on port B pin 5
      .
      .
      .
      //____________________________________________________________________________________________________ _________________

      void main(void)
      {
      unsigned char n;
      .
      .
      .

      // SOMO-II test

      set_volume(30);
      play_folder_track(1,5);
      wait_end_of_play;
      play_folder_track(1,1);
      ad_aeternum;

      }

      //____________________________________________________________________________________________________ _________________

      void somo_cmd(unsigned char cmd,unsigned char feedback,unsigned char para1,unsigned char para2)
      {
      unsigned int chk;
      unsigned char chk1;
      unsigned char chk2;

      chk = 0xFFFF - ((unsigned int)cmd + (unsigned int)feedback + (unsigned int)para1 + (unsigned int)para2) + 0x0001;
      chk1 = (unsigned char)(chk >> 8);
      chk2 = (unsigned char)chk;

      putchar(0x7E);
      putchar(cmd);
      putchar(feedback);
      putchar(para1);
      putchar(para2);
      putchar(chk1);
      putchar(chk2);
      putchar(0xEF);

      delay_ms(100);
      }

      //____________________________________________________________________________________________________ _________________

      unsigned char getpin(char *door)
      {
      //Reads the port pin (high = 1, low = 0)

      unsigned char x,n,pta;

      pta = door[0]; //Port
      n = door[1] - 48; //Pin
      switch(pta)
      {
      case 'A':
      x = TSTBIT(PORTA.IN,n);
      break;
      case 'B':
      x = TSTBIT(PORTB.IN,n);
      break;
      case 'C':
      x = TSTBIT(PORTC.IN,n);
      break;
      case 'D':
      x = TSTBIT(PORTD.IN,n);
      break;
      case 'E':
      x = TSTBIT(PORTE.IN,n);
      break;
      case 'F':
      x = TSTBIT(PORTF.IN,n);
      break;
      case 'H':
      x = TSTBIT(PORTH.IN,n);
      break;
      case 'J':
      x = TSTBIT(PORTJ.IN,n);
      break;
      case 'K':
      x = TSTBIT(PORTK.IN,n);
      break;
      case 'Q':
      x = TSTBIT(PORTQ.IN,n);
      break;
      case 'R':
      x = TSTBIT(PORTR.IN,n);
      break;
      }
      return(x);
      }

      //____________________________________________________________________________________________________ _________________

      Comment


      • #4
        Huu! I forgot the attached files
        Attached Files

        Comment


        • #5
          another file
          Attached Files

          Comment


          • #6
            another file - 3
            Attached Files

            Comment


            • #7
              Hello Pardini,

              Glad to know you've made it work with your microcontroller.
              Your folder naming is correct, so the uSD could be the cause for that issue.
              Though its hard to know the exact cause.
              You could also try creating all the folders first, then fill them with .mp3 files.

              Best Regards,

              Comment

              Working...
              X