cmucam3-hardware (#1) - accessing TX2 and RX2 (#50) - Message List

accessing TX2 and RX2

Hi,

On pg 10 of the datasheet: Expansion Port GPIO

How can i access TX2 and RX2 and use them as an output port?

What is their output form, if not level shifted?

Thanks...

  • Message #131

    Since it is not level shifted, like uart 0, it will send a signal between 0 and 3.3 volts. You would need to connect a level shifter ( TTL->USB Serial or TTL->Serial Port) to connect it to a computer or another level shifted source. Many embedded devices like microcontrollers can communicate using TTL serial directly. Be careful though, because if you connect a level shifted device to a TTL device, the TTL device will likely get fried.

    To use the second port, first define a file pointer for it:

    FILE *p;
    

    Next configure it in the same way that you would configure uart 0 (you can configure both!):

    cc3_uart_init(1,CC3_UART_RATE_115200, CC3_UART_MODE_8N1, CC3_UART_BINMODE_TEXT);
    

    Open it:

    p=cc3_uart_fopen(1,"r+");
    

    Then you can use it with fprintf, fpuc, fgetc, fscanf etc like this:

    fprintf( p, "This is a string...\r\n" );
    

    Keep in mind, you can use both uart 0 and 1 if you keep the uart 0 init code. You might want to make *p global or at least make sure to pass it to your functions that need to use it.

    -Anthony

    • Message #361
    • Message #142

      I am actually implementing h-bridge drivers and I have used up the servo ports. I need two more GPIO signals for one more driver.

      Can I control the TX2 and RX2 pins separately, just to send a high and low signals.

      Thanks..

      • Message #144

        You can use the two pins as GPIO. The normal cc3 gpio functions probably don't work with those pins however configuring the normal arm registers is not that difficult. RX2 is P0.9 on the processor and TX2 is P0.8. So RX2 has a bit mask of 0x00000100 and TX2 is 0x00000080. First you need to set the data direction register to make them output. You may also need to configure the PCB (pin configuration block) to make sure they are GPIO. Finally you can directly set the GPIO_IOSET and GPIO_IOCLR registers to toggle them. I think the code should be something like this (but I have not tested it):

        #define RX2_PIN  0x00000100
        #define TX2_PIN  0x00000080
        
        // If you look in cc3_camera_init () in hal/lpc2106-cmucam3/cc3.c, 
        // you see configuration of the PCB for uart 0 and uart 1.  
        // You want to remove the uart 1 so that you can use it as 
        // gpio.  So you could either change it there, or have this command later
        // in your main code after all of the camera_init() stuff has happened.
        // Keep in mind that changing camera parameters etc might reset the gpio
        // state. If that turns out to be the case, then you should edit 
        // hal/lpc2106-cmucam3/cc3_pin_defines.h and add your mask into the defaults.
        
        REG (PCB_PINSEL0) = (REG (PCB_PINSEL0) & 0xFFFF0000) | UART0_PCB_PINSEL_CFG;
        
        // OR in to make it an output
        // 1 is output, 0 is input
        REG(GPIO_IODIR) = _CC3_DEFAULT_PORT_DIR | RX2_PIN | TX2_PIN;  
        
        REG (GPIO_IOSET) = RX2_PIN;   // set RX2 pin
        REG (GPIO_IOCLR) = RX2_PIN;   // clr RX2 pin
        
        

        That might not be totally correct, but it has the basic steps you need to do. Make sure to checkout the GPIO section of the lpc2106 datasheet. Sometimes this can be a little tricky, but it is definitely possible.

        -Anthony

        • Message #145

          I defined the pins in cc3_pins_define.h and i removed the uart1 from the cc3.h file. then i built it all.

          now im trying to run the REG(GPIO_IODIR) = _CC3_DEFAULT_PORT_DIR | RX2_PIN | TX2_PIN;

          REG (GPIO_IOSET) = RX2_PIN; // set RX2 pin REG (GPIO_IOCLR) = RX2_PIN; // clr RX2 pin

          in my main file, but when i build it these error messages appear:

          CC lpc2106-cmucam3_buildfiles/main.o

          ain.c: In function 'main':

          ain.c:37: error: implicit declaration of function 'REG'

          ain.c:37: warning: nested extern declaration of 'REG'

          ain.c:37: error: 'GPIO_IODIR' undeclared (first use in this function)

          ain.c:37: error: (Each undeclared identifier is reported only once

          ain.c:37: error: for each function it appears in.)

          ain.c:37: error: '_CC3_DEFAULT_PORT_DIR' undeclared (first use in this function

          ain.c:37: error: 'RX2_PIN' undeclared (first use in this function)

          ain.c:37: error: 'TX2_PIN' undeclared (first use in this function)

          ain.c:38: error: 'GPIO_IOSET' undeclared (first use in this function)

          ain.c:39: error: 'GPIO_IOCLR' undeclared (first use in this function)

          ain.c:97: warning: unused variable 'my_pix'

          ain.c:16: warning: unused variable 'fp'

          ain.c:15: warning: unused variable 'c'

          ake: *** [lpc2106-cmucam3_buildfiles/main.o] Error 1

          • Message #160

            If you use those functions directly from main, you need to include cc3_pin_defines.h as well as LPC2100.h. As a quick hack, you could try adding a relative path at the top of your main file like (you might need a different number of ../..'s to get the path right):

            #include "../../hal/lpc210-cmucam3/cc3_pin_defines.h"
            #include "../../hal/lpc210-cmucam3/LPC2100.h"
            

            -Anthony

            • Message #501

              Hi Anthony,

              I follow all the step you mention above, and still couldn't set RX2 pin to Ouput.

              here is my code http://www.cmucam.org/discussion/1/200

              please let me know if i missed anything else.. i am wondering is the address is correct? where do i look up address location table? any hints would be greatly appriecated.

              thanks

            • Message #502

              In LPC2106 datasheet page 82 , IODIR:Direction control bits (0 = INPUT, 1 = OUTPUT). Bit 0 controls P0.0 ... Bit 31 controls P0.31

              Can i do this

              REG(GPIO_IODIR) = _CC3_DEFAULT_PORT_DIR | BIT(9) | BIT(8);

              instead of defining the pin address. Any clue would be great.

              Thanks,

              Ammar

              • Message #503

                I'm not sure what BIT() is defined to be (it might work). What you want it essentially for BIT(x) to be defined as (1<<x). So if you put | (1<<9) | (1<<8) that should work fine.

                The other thing to take a look at is the PCBPIN_SEL registers. These registers determine which peripherals are active. For example GPIO could be active, or the UART could be active on those pins.

              • Message #504

                Thanks....

                i will try that out... in that mean time i am hitting brick wall when come to configure PCB_PINSEL0. What address should i use ?

                is it right to do this

                REG (PCB_PINSEL0) = (REG (PCB_PINSEL0) & 0xFFFF0000) | UART0_PCB_PINSEL_CFG | (0<<19)|(0<<18) | (0<<17)|(0<<16) ; // for P0.9 | P0.8

                i dont really get it what should i written for PCB_PINSEL0 http://winarm.scienceprog.com/arm-mcu-types/interrupt-system-of-arm-lpc2000-microcontrollers.html

                another help would be great.. thanks cheers

                • Message #697

                  Hi, first my english is quite bad, so if you read something horrible...sorry.

                  I'm trying to do the same, i need two lines to emulate a I2C bus. I think about to use the RX2 and TX2 pins. The bit mask you need to set the GPIO_DIR are:

                  TX2 (P0.8) = 0x00000100 RX2 (P0.9) = 0x00000200

                  I don't do it yet, because i haven't the I2C adapter done.