This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Modified the GPIO Test Demo Code, need some help asap!

Other Parts Discussed in Thread: TMS320C5505, TMS320VC5505

I downloaded the GPIO code from the c5505 Google Docs page -- http://code.google.com/p/c5505-ezdsp/ -- and stock, it seemed to be running just fine.

I modified the code to better suit the application i have planned for the GPIO pins. Essentially, 3 of these pins, GPIO[22:24], will be fed by a 3-way rotary switch that will be sending the required 3.3V for a logical 1. Below is the code i have attempted to run.

 

#include <stdio.h>
#include "tistdtypes.h"

#define EBSR *((volatile ioport Uint16 *)(0x1C00))       //Pin-mux selection register
#define IODIR1 *((volatile ioport Uint16 *)(0x1C06))     //IO direction selection
#define IODIR2 *((volatile ioport Uint16 *)(0x1C07))     //IO direction selection
#define IOINDATA1 *((volatile ioport Uint16 *)(0x1C08))  //GPIO input data register1
#define IOINDATA2 *((volatile ioport Uint16 *)(0x1C09))  //GPIO input data register2

void main (void)
{
  Uint16 read_input;
 
  //set mux-selection for GPIO[22:24]
  EBSR |= 0x000E; 
 
// set GPIO[22:24] as inputs
   IODIR2 |= 0xFE3F;

  while(1)
  {  
    //read the input port
    read_input = IOINDATA2;
   
    //check the status of GPIO[22:24]  
    if (read_input && 0x0040){
      //if ((read_input & 0x0040) == 1){
        printf("worked 22 \n");
    }
    else if (read_input && 0x0080) {
      //else if ((read_input & 0x0080) == 1){
        printf("worked 23 \n");
    }
    else if (read_input && 0x0100) {
      //else if ((read_input & 0x0100) == 1){
        printf("worked 24 \n");
    }
    else {
        printf(" nope :( \n");
    }      
  } 
}

I have tried two different ways to check read_input against the value i'm looking for using bit-wise AND and Logical AND; both do not seem to work.
I have a 3.3V DC supply on a bread-board that i'm using to feed these GPIO pins as well, so I believe the voltage level should be ok.

Also, it compiles with two warnings, which I am not sure if they are critical or not.

1) creating output section ".cio" without a SECTIONS specification
2) creating ".sysmem" section without default size of 0x7d0; use the -heap option to change the default size

I could really use some help because i've been stuck on this for too long :(

Thanks for reading!

  • I would suggest that you pick up a book on C as a reference.  Your question is not specific to any TI processor and more about how to write the program to accomplish the task you desire.  I'll try to help out there, but again, I would suggest a reference book.  I always keep one handy for myself as well.

    There are a couple of ways to do this, depending on how many states of the 3 pins you are interested in knowing.  A switch-case statement may be applicable if you end up expanding this to more states.  Right now, it looks like you are prioritizing your actions based on GPIO[22] being set to logic 1 over GPIO[23] and so on.

    Try the following :

    if ((read_input & 0x0040) == 0x0040) {
    ...
    }
    etc.

    You should also address the sections errors as well.  #1 can be fixed with the linker command file modification to allocate the .cio section to a memory segment.  The C/C++ Optimizing User's Guide should have some guidance on where to place this.  I suspect you may find info for #2 there as well.

     

  • Brandon,

    Thank you very much for the response. I actually do have a nice C book i keep handy and reference often :)

    I don't think I mentioned this in my first post, but the point of this GPIO test code modification was just to see if i could successfully set the different GPIO pins as high using the external DC power supply. Once I know that this is working fine, I'm planning to integrate a similar switching method into my larger program, which is attempting to model 3 different guitar amps on the TMS320C5505 eZDSP. I'm hoping to use this as a switching method for going between the 3 different amplifier models using a rotary switch on the amplifier chassis.

    The reason I posted this in the c5000 forum section is because I believe I have setup the External Bus Selection Register for GP22, 23, and 24 correctly by assigning 0x000E to EBSR, which would make bits 1, 2, and 3 a value of 1 turning these pins ito GPIOs not EMIF address pins. I picked this up from page 54 of the tms32c5505 tech sheet -- http://focus.ti.com/lit/ds/symlink/tms320c5505.pdf.

    I also believe i have the GPIO Direction Register, IODIR2, configured correctly,  such that 0xFE3F will make GP[22:24] inputs, not outputs.
    Assuming all of that is correct, my logic was that if i could detect a 1 on pin 22, the variable read_input should contain the result 0x0040. If a 1 was detected on pin 23, read_input would be 0x0080 and if a 1 was detected on pin 24, read_input would be 0x0100. Leaving the internal pull-down resistors enabled would make the two pins not currently in use, say 22 and 23, would be a logical zero while pin 24 would be a logical 1.
    I pulled this information off of this document -- http://focus.ti.com/lit/ug/sprufo4/sprufo4.pdf

    I just wanted to see if there was something i am setting incorrectly or if my assumptions about the GPIO pin values were incorrect.

    My thinking was that the actual switching block of code would look more like this (incorporating your suggestion):

        if ((read_input & 0x0040) == 0x0040){ // select mode 1
            mode_1 = 1;
            mode_2 = 0;
            mode_3 = 0;
        }
        else if ((read_input & 0x0080) == 0x0080) { //select mode 2
            mode_1 = 0;
            mode_2 = 1;
            mode_3 = 0;
        }
        else if ((read_input & 0x0100) == 0x0100){ // select mode 3
            mode_1 = 0;
            mode_2 = 0;
            mode_3 = 1;
        }

      else { // if the switching fails
            mode_1 = 1;
            mode_2 = 0;
            mode_3 = 0;
    }      

    I apologize if this request seems trivial. I'm still a student finish my undergraduate degree so I know I have a lot to learn about writing programs and I sincerely appreciate you taking the time to read my information.

    Thank you.

    George

  • Does your new implementation work?  Another quick test to see if you have the configuration of the registers setup correctly is to set a breakpoint on your if-else statement and check what the actual value of read_input is when you look at it in a watch window.  If it is not what you expect it to be, then your debug needs to be first pointed to the configuration of the peripherals.

  • I actually did manage to get it working, but it took quite a bit of finagling. I actually connected each of the pins to a separate 1k resistor to ground on the breadboard/DSP ground. Then, I could supply my voltage to which ever pin i chose and it worked, but with a caveat.

    I tested it using the GPIO test code and in order for this to work consistently i needed to assign EBSR and IODIR2  like so:

    EBSR = 0x000E;
    IODIR2 = 0xFE3F;

    Then, when i implemented this switching method within my amplifier program i used the same hardware setup, but i had to set those two variables differently or else the audio would get cut out completely.

    EBSR |= 0x000E;
    IODIR2 |= 0xFE3F;

    It seems strange, but at least it's working. Any thoughts?
    Thanks for your help.

    George

  • I would assume that the audio codec connected to the TMS320VC5505 is via one of the serial interfaces influenced by the EBSR register.  The second set of statements, performs a read-modify-write operation on EBSR and IODIR2.  The first set of statements simply assigns these registers with the values indicated.

  • ahh! that would make sense! I was unfamiliar with the |= operator, but that definitely clarifies it for me.

    I noticed my program is now having a minor issue, which i'm not sure what it could be related to.
    When I connect the eZDSP to my computer and run the program all the external switching works perfectly and I can access each of the 3 guitar amp models tied to GP[22:24] exactly how I was hoping to.

    So, what I did next was to flash the program into the EEPROM so I could integrate this eZDSP in with the rest of the project. After flashing the program in successfully, i plugged it into my laptop for power and hooked up all the switching/DC power supply cabling. The modes attached to GP22 and GP23 switch just as they did before, but when I switch to GP24, the audio sounds extremely noisy and you can't make out the signal at all.

    I used hex55.exe and the following commands for creating the binary file from my respective .out file:
    Normal 0 false false false EN-US X-NONE X-NONE

       hex55.exe -boot -v5505 -serial8 -b –i AmpModels.out -o AmpModels.bin

    I flashed it in CCS4 using the programmer_USBKey.out file  and everything appeared to run normally.

    What could be causing this?

    Thanks!


    George

     

  • Still having the same issue. I went back into my code and changed the pins from GP22, GP23, and GP24 to GP22, GP23, and GP25 just to see if it was pin24 that was having an issue. I also made sure to update the EBSR and the correct comparison for the IOINDATA2.

    Once again, the pins worked exactly as they should when i ran the code on the eZDSP in CCS, but when i flashed the updated program onto the eZDSP, pins 22 and 23 switch perfectly, but when i switch to pin 25 the audio gets corrupted beyond comprehension.

    Any suggestions on what could possibly be going wrong?

    Thanks!

    George

  • I think i figured out what was wrong. I tried a different block of code for the model that was getting the audio corrupted and now it works just fine (both in CCS and once it's flashed).

    Now i'm just curious why the model would have the audio corrupted only when it was flashed, but not in CCS?

  • Can you please share the exact block of code you used for declaring and using the GPIO's for switching?

    I'm working on a similar project (audio effects) and wish to do a similar switching style (only with 4 pins, each activating or deactivating an effect). As I am fairly new to this, your code would help me a lot - write now I'm suffering from coder's blockage.

    Thanks!

  • My code was based off the Audio Filter Demo and this first block of code was used in the main_bypass1.c file before the void main(void) call:

    Uint16 plexi = 0;
    Uint16 bman = 1;
    Uint16 recto = 0;

    Inside the same .c file, but in the void main(void) i added these lines:

        EBSR |= 0x000E;        // EBSR for GPIO[22:24]
        IODIR2 |= 0xFE3F;    // GPIO[22:24] as inputs

    I also had to define the plexi, bman, and recto variables inside the rtc_bypass1.c as externs, so:

    extern Uint16 plexi;
    extern Uint16 bman;
    extern Uint16 recto;

    Next, in the rtc_bypass1.c I used this code for switching

    interrupt void RTC_Isr(void)
    {
        Uint16 temp;

        // clear RTC int flag
        IFR1 = 0x0004;
       
        temp =RTC_STAT;
        RTC_STAT = temp;
       
        read_input = IOINDATA2;
       
        if ((read_input & 0x0040) == 0x0040){    // pin 22
            bman = 1;    //GPIO[22]
            plexi = 0;
            recto = 0;
        }
        else if ((read_input & 0x0080) == 0x0080){    //pin 23
            bman = 0;
            plexi = 1;    //GPIO[23]
            recto = 0;
        }
        else if ((read_input & 0x0100) == 0x0100){    // pin 24
            bman = 0;
            plexi = 0;
            recto = 1;    //GPIO[24]
        }
        else { // If the switching fails
            bman = 1;   
            plexi = 0;
            recto = 0;
        }
    }

    I think that's all the code I used.

    I also had to setup each pin (22 - 24) so they were connected to a 1 k-ohm resistor to ground and then i used around 3.3V-DC to power the switching through a 3-way rotary switch. You can use any voltage, i believe, as long as it's at least 1.8V-DC.

    There was a slight delay when turning the rotary switch, but it definitely works.

    Hope it helps.

     

     

     

  • Thanks for the fast response! This actually helps A LOT.

  • George,

    I came across your post to the forum and had noticed that there is no debounce logic for the switch. I don't know much about the circuitry or inputs, but please be advised that anytime that you use switches you must investigate the debounce effects and this typically requires additional software to handle this.

    Here's a good web link to find out more about debouncing:

    http://www.ganssle.com/debouncing.htm

    I also believe the ezDSP and EVM source code have a few examples to handle the debouncing.

  • hey, my friend, now i'm doing a C5505 audio project. i need 5 input pins to implement, for example: pin 21 - 25. i have check the datasheet , i still can' t find value of  EBSR and   IODIR2. and how can i check the status of these pins. Can u giv me some tips on it. thks a lot.

  • Hello,

    It has been quite some time since i've used this code or the hardware, but all of my source code is located here:

    https://sites.google.com/a/temple.edu/dspamp/documentation-2/FinalDSPModelCode.zip

    or https://sites.google.com/a/temple.edu/dspamp/documentation-2/

    In that .zip file look for main_bypass1.c under the project folder. This is where I do all of the switching. You should be able to load the code and get it to work.

    Good luck!