interfacing with GPS through serial port

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

interfacing with GPS through serial port

Post by deniska »

I am trying to connect Holux GPSlim 236 to my PSP through a serial port for my mapping project (http://deniska.dcemu.co.uk/)
I am using following scheme (receive only) without any luck so far:

Code: Select all

Holux GND (pin1) ----------------------------> PSP pin2 
Holux RXD (pin4) --> [20K-2K resistor] ---> PSP pin6 
According to the manual (http://www.holux.com/product/res/GPSlim236-Manual-E.zip) pin 4 is supposed to "Receive Data. Form peripheral to organizer.(Voltage level is 3.3V ~5.0V)."

Tests with lua's port echo prog dont show any indication that the communication is working: I only get 1 sec dots...
I tried resistors from ~20k going down to 2K.. I am a little afraid to go lower than 2K though..

Could someone look at the specs and tell me if this is possible at all and what I am doing wrong...


Would appreciate any suggestions/leads...
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

deniska... Didn't I post on the dcemu forums about this?

1) make sure you have headphones connected to the headphone socket. The serial port is only on/activated when headphones are attached.
2) default baud rate for the GPSlim 236 on the serial output is 38400 or 57600 - I forget which.
3) pin 3 is the output from the PSP, pin 6 is the input to the PSP. Check http://nil.rpc1.org/psp/remote.html
4) Pin 4 on the GPSlim is output from the GPS. Pin 3 is Input to the GPS.
5) You might not get any output from the GPS unless you have a valid GPS lock. Check with Bluetooth connections. GPSlim 236 orange light will blink when you have a GPS lock.

Code: Select all

Holux GND (pin1) ----------------------------> PSP pin2
Holux RXD (pin4) --> [20K-2K resistor] ---> PSP pin6 
should be right otherwise... I'd test but I haven't bothered to make a cable between the PSP and the GPSlim 236. It works fine with my FT232R based cable though.
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Thanks for quick response...

1) I've tested with plug ripped off Intec remote control (http://www.jr.com/JRProductPage.process?Product=4054891) since it's cheaper than the original. So the headhone plug was in but nothing was connected to it. Do I actually need to close the audio circuit with some low value resistor to make it work? - I don't really want actual headphones in this setup.

5) The GPS seemed to be spitting NMEA sentenses via blue tooth to my PC running GPS viewer.. There was some signal ~ 2.2V on the RXD pin of the GPS. I measured with a cheap multimeter, so the voltage value is probably off because of the frequency...


Which program do you use to test your gps connection???
Can you share the code/binary?

Thanks again,

DENIS

futaris wrote:deniska... Didn't I post on the dcemu forums about this?

1) make sure you have headphones connected to the headphone socket. The serial port is only on/activated when headphones are attached.
2) default baud rate for the GPSlim 236 on the serial output is 38400 or 57600 - I forget which.
3) pin 3 is the output from the PSP, pin 6 is the input to the PSP. Check http://nil.rpc1.org/psp/remote.html
4) Pin 4 on the GPSlim is output from the GPS. Pin 3 is Input to the GPS.
5) You might not get any output from the GPS unless you have a valid GPS lock. Check with Bluetooth connections. GPSlim 236 orange light will blink when you have a GPS lock.

Code: Select all

Holux GND (pin1) ----------------------------> PSP pin2
Holux RXD (pin4) --> [20K-2K resistor] ---> PSP pin6 
should be right otherwise... I'd test but I haven't bothered to make a cable between the PSP and the GPSlim 236. It works fine with my FT232R based cable though.
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

I haven't tested the receiver on the PSP, as I haven't bothered to make a cable up. However, I've used it Minicom in Linux and Hyperterminal in Windows, using a FT232R cable (http://www.ftdichip.com/Products/FT232R.htm) to test that the serial port works.

If you use the serial port, then another device can still connect via bluetooth. I've had both my Smartphone via Bluetooth and my laptop via Serial running GOOPS (http://sites.onlinenw.com/goops/goops.php) connected at the same time.

I haven't even tried to use serial on the headphone connector yet...
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

Check /usr/local/pspdev/psp/sdk/samples/debug/sio for a pspdev serial io sample or http://forums.ps2dev.org/viewtopic.php?t=4087 for a lua sample.

Like the Lua thread says, I'd be surprised if you could get it to work above 2400bps. However, the pspdev one should work fine...

psplink_manual.pdf says baud rates 4800, 9600, 19200, 38400, 57600 and 115200 are supported... It's in the psplink zip.
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

file:///usr/local/pspdev/psp/sdk/doc/html/sio_8c.html for the sio documentation.
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

Alright, I whipped up a small serial cable, and modified the sio example to spit out the serial GPS data @ 38400bps to the PSP's screen.

It gives me the same data that I get from minicom. Doesn't do any GPS parsing or anything.

http://files.futaris.org/psp/pspgpslim2 ... lim236.zip

Reboot the PSP to exit the program.
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

Oh and one other thing. You might not need a headphone connected to that port. I think it only turns on VCC (2.5V).

NB, I didn't put a resistor or anything in series with the GPS TX and the PSP RX. The PSP should be 3.3V tolerant...
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

futaris wrote:Oh and one other thing. You might not need a headphone connected to that port. I think it only turns on VCC (2.5V).

NB, I didn't put a resistor or anything in series with the GPS TX and the PSP RX. The PSP should be 3.3V tolerant...
Thanks for the effort you put in to this...
I recompiled your prog w/o any problems - gonna try to connect again once I get home and let you know if it works...
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Ok,
I got the communication going once I connected GPS's TXD (pin 3) to PSP's RX (pin 6).

The holux's description of TXD vs RXD in the manual is rather puzzling...

Anyway,
When using the sio sample that you sent I get batches of weird characters on PSP's screen every second, approximately 2.5 lines every second...
Is this some kind of encoding or am I screwing something up in the connection?
I was kind of hopping to see somethings like:
$GPGSV,3,3,12,16,00,000,,05,.............


Yet another puzzle: if I use EBOOT, compiled by me from the code, you provided in the zip I get just 3-4 characters at a time (not 2-3 lines like with your EBOOT).. I ran the toolchain script just a few days ago so I must have the latest sdk version.. could you check which one you have?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

You might have the wrong baudrate, or maybe your GPS chipset is in the SiRF binary mode? If you try connecting it to a PC (through a max233, ft245, or similar) you'll be able to test different baudrates more easily and verify that it's not a PSP issue.
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Ok, I finally got this thing working with 1K resistor between PGS and PSP..
Using the sio program from the zip I can finally see NMEA sentences, streamed to my PSP :-)

Work of caution though: don't try anything lower than 1K - You'd risk bricking your PSP....
I tried some low value resistor and my psp went black for 1 minute...
Fortunatelly, I was able to bring it back to life...
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

futaris:
I still have one more puzzle to solve:
My latest setup works with the EBOOT from the zip that you provided above - I get normal NMEA sentences on the screen.
But then I use the EBOOT, compiled on my cygwin, box I get only 3-4 characters a second. It looks like most of the characters are skipped for some reason. Here is a sample of what I get:
$00,$0,$00$..$P,0323G$.,$G,6$58,$54,$6 and so on


I tried to build a few versions of SDK (from 10 months ago- to current) under sygwin and recompile, but still I get the same output...
Of course I played with different bauds but 38400 is the only one, giving me more or less recorgnizable characters... but at any baud I only get 3-4 charachters per second...

Any ideas? Is there anything else in your EBOOT that did not get to the source, provided in the zip? Under which environment did you build it?

[EDIT] Nevermind, I fugured out what the problem was - looks like reading the controls was slowing down the read loop.
Here is the final barebone code sample that works for me:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>

PSP_MODULE_INFO&#40;"GPSCOMM", 0x1000, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int main&#40;void&#41;
&#123;
        pspDebugScreenInit&#40;&#41;;
        pspDebugSioInit&#40;&#41;;
        pspDebugSioSetBaud&#40;38400&#41;;

        pspDebugScreenPrintf&#40;"PSP GPSlim 236 test&#58;\n"&#41;;

        double i=0;
        int ch;
        while&#40;i<20000000&#41;
        &#123;
                i++;
                ch = pspDebugSioGetchar&#40;&#41;;
                if&#40;&#40;ch >= 0&#41; && &#40;ch != '\r'&#41;&#41; &#123;
                        pspDebugScreenPrintf&#40;"%c", ch&#41;;
                &#125;

        &#125;

        sceKernelExitGame&#40;&#41;;

        return 0;
&#125;
Makefile:

Code: Select all

TARGET = pspgpslim236
OBJS = main.o

USE_PSPSDK_LIBC = 1

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = GPSlim236

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

LIBS += -lpsphprm_driver
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

Yep. That should work fine. I think I had #if 0's around the controller part when I compiled it and must have deleted the lines when I compiled it. NB, polling the serial port constantly eats up the CPU, since there's no CPU time for anything else to run.

I don't know if there is a way to generate an interrupt whenever a character is in the serial FIFO, but that would be the best rather than constantly polling the serial port.
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

FYI,

I put up a little GPS data viewer, which parses the data and displays it ont the screen every second:

Image

The code and binaries are here:
http://deniska.dcemu.co.uk/bin/gps_viewer.zip
If the link does not take you to the zip - try to paste it in to your browser window.

Here is how the whole setup looks (I should probably get a thinner usb cable and cut the length a bit ):
Image
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

futaris wrote:I don't know if there is a way to generate an interrupt whenever a character is in the serial FIFO, but that would be the best rather than constantly polling the serial port.
Psplink does this, so you can check the source for how to do it.
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

jimparis wrote:
futaris wrote:I don't know if there is a way to generate an interrupt whenever a character is in the serial FIFO, but that would be the best rather than constantly polling the serial port.
Psplink does this, so you can check the source for how to do it.

I tried to borrow the inerrupt handling logic from PSPlink and insert it in to my code, but for some reason it does not work: it seems to hang on the first read...

Any ideas would be apreciated...

here is what was added to main.c, zippped in the reference in one of the posts above:

Code: Select all

static SceUID g_eventflag = -1;


static int intr_handler&#40;void *arg&#41;
&#123;
        u32 stat;

        /* Read out the interrupt state and clear it */
        stat = _lw&#40;0xBE500040&#41;;
        _sw&#40;stat, 0xBE500044&#41;;

        sceKernelDisableIntr&#40;PSP_HPREMOTE_INT&#41;;

        sceKernelSetEventFlag&#40;g_eventflag, EVENT_SIO&#41;;

        return -1;
&#125;




int sioReadChar&#40;void&#41;
&#123;
        int ch;
        u32 result;

        ch = pspDebugSioGetchar&#40;&#41;;
        if&#40;ch == -1&#41;
        &#123;
                sceKernelEnableIntr&#40;PSP_HPREMOTE_INT&#41;;
                sceKernelWaitEventFlag&#40;g_eventflag, EVENT_SIO, 0x21, &result, NULL&#41;;

                ch = pspDebugSioGetchar&#40;&#41;;
        &#125;

        return ch;
&#125;

..............................

int main&#40;void&#41;
&#123;
        pspDebugScreenInit&#40;&#41;;
        pspDebugScreenSetBackColor&#40;0x00007700&#41;;
        pspDebugSioInit&#40;&#41;;
        g_eventflag = sceKernelCreateEventFlag&#40;"SioShellEvent", 0, 0, 0&#41;;
        sceKernelRegisterIntrHandler&#40;PSP_HPREMOTE_INT, 1,&#40;void*&#41; intr_handler, NULL, NULL&#41;;
        sceKernelEnableIntr&#40;PSP_HPREMOTE_INT&#41;;
        /* Delay thread for a bit */
        sceKernelDelayThread&#40;2000000&#41;;
        pspDebugSioSetBaud&#40;38400&#41;;


.................
while &#40;1&#41; &#123;

ch = sioReadChar&#40;&#41;;
//do something with it...

&#125;
&#125;

[edit] Just realized that the call to ceKernelRegisterIntrHandler returns some huge negative number instead of 0..
hmmm....
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

Just quickly...

I think you need to call _sioInit:

static void _sioInit(void)
{
/* Shut down the remote driver */
sceHprmEnd();
/* Enable UART 4 */
sceSysregUartIoEnable(4);
/* Enable remote control power */
sceSyscon_driver_44439604(1);
}

just look at

sioInit in trunk/psplink/psplink/sio.c
futaris
Posts: 45
Joined: Wed Dec 28, 2005 7:47 am

Post by futaris »

Probably more than likely the remote control handler is still there, until you call sceHprmEnd();
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

futaris wrote:Just quickly...

I think you need to call _sioInit:

static void _sioInit(void)
{
/* Shut down the remote driver */
sceHprmEnd();
/* Enable UART 4 */
sceSysregUartIoEnable(4);
/* Enable remote control power */
sceSyscon_driver_44439604(1);
}

just look at

sioInit in trunk/psplink/psplink/sio.c
Of course, I tried that.. but it id not work for me for some reason...
I was testing it through psplink...
Charles
Posts: 11
Joined: Fri Jul 28, 2006 5:09 am
Location: SC

4800 8N1

Post by Charles »

The software that you (deniska) wrote, will it work with NMEA sentences @ 4800 baud?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

deniska, the sceKernelRegisterInterruptFunction checks that your handler is in kseg0 otherwise it returns 0x80020065 as an error code. I assume you are running this in a kernel elf and not a kernel prx. So either:

1) Make this a kernel prx or...
2) The dirty way, do void *func = (void *) ((unsigned int) intr_handler | 0x80000000); and pass func instead.
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

TyRaNiD, thanks...
I tried the "dirty way" and it worked fine...
Warren
Posts: 173
Joined: Sat Jan 24, 2004 8:26 am
Location: San Diego, CA

Post by Warren »

I just bought one of the GPSlim 236 devices and want to hook it up and play around, you should add your application to PSPWare in SVN deniska.

If you have a new version of your current software I'd love to take a look at it
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Nothing new so far, but I do make some slow progress with my mapping application, so keep checking http://deniska.dcemu.co.uk/ for updates...
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Hey, perhaps someone with better knolege of HW rendering routines can give me a hand.

I am trying to implement map rotation feature for my GPS navigation software (details could be found here: http://deniska.dcemu.co.uk)

Most of my current rendering is done with graphics.h library borrowed from lua player

This link points to a simplified sample of what I do in my mapping program:
http://deniska.dcemu.co.uk/bin/rotate_map_problem.zip
(paste the link in to your browser's address entry box if it does not work directly)

Basically, I write current mapset in to a 512x512 img buffer and then "rotate" it with:

Code: Select all

sceGuTexImage&#40; 0, img->textureWidth, img->textureHeight, img->textureWidth, img->data &#41;;

        sceGumDrawArray&#40; GU_TRIANGLE_STRIP,  GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, quad &#41;;
This works fine, but then I try to blit a transparent image on top of the rotated map using blitAlphaImageToScreen() from graphics.lib and that image seems to always go under the rotated map...
The non-transparent image blit works just fine...

The blitAlphaImageToScreen() method uses:
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);


Any help would be greatly appreciated....
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

Disable depth testing. (Line 81/82 in the sample.)

Code: Select all

//	sceGuDepthFunc&#40; GU_GEQUAL &#41;;
//	sceGuEnable&#40; GU_DEPTH_TEST &#41;;
I ran into the same thing with my pspgl 2d stuff, worked on pc but on psp that screwed it up.

Think I'll have to build myself a GPS, after running that sample.... It looks REALLY GOOD :))
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Thanks alot, danzel!
I knew that must have been something really simple...

TyraNid, thank you for the tip on interrupts - I tried it and it worked...

Really appreciate your help!
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Re: 4800 8N1

Post by deniska »

Charles wrote:The software that you (deniska) wrote, will it work with NMEA sentences @ 4800 baud?
According to people's reports -it does.. but you'll need to change the baud rate and recompile... of course, it will be configurable in my map viewer program..
Namlas
Posts: 2
Joined: Tue Aug 15, 2006 2:05 am

a Keybord to interface sony's firware using the remote port

Post by Namlas »

hi,
I was just wonderwing would it be possible to interface with sony's firware virtual keyboard with a actually keyboard through the psp remote port.the virtual keyboard on the psp requires the user to press the x button and use the d-pad. for example, for the letter "b" the user must press thex button twice. Would it be possible to connect up a keyboard(normal pc) to the psp remote and when the letter b is pressed on the keyboard the signal is converted to a command that will tell the psp the x button has been pressed twice , hence interfacing with the txt entry with sony's firware ? Or is this an impossible and stupid idea?
Post Reply