forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

interfacing with GPS through serial port
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Fri Jul 21, 2006 12:16 pm    Post subject: interfacing with GPS through serial port Reply with quote

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:

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...
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 2:05 pm    Post subject: Reply with quote

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:

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.
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Fri Jul 21, 2006 2:53 pm    Post subject: Reply with quote

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:

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.
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 3:02 pm    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 3:14 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 3:19 pm    Post subject: Reply with quote

file:///usr/local/pspdev/psp/sdk/doc/html/sio_8c.html for the sio documentation.
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 4:55 pm    Post subject: Reply with quote

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/pspgpslim236/pspgpslim236.zip

Reboot the PSP to exit the program.
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 4:57 pm    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Sat Jul 22, 2006 4:20 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Sat Jul 22, 2006 11:41 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Sat Jul 22, 2006 4:19 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Sun Jul 23, 2006 6:28 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Sun Jul 23, 2006 1:26 pm    Post subject: Reply with quote

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:

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

PSP_MODULE_INFO("GPSCOMM", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

int main(void)
{
        pspDebugScreenInit();
        pspDebugSioInit();
        pspDebugSioSetBaud(38400);

        pspDebugScreenPrintf("PSP GPSlim 236 test:\n");

        double i=0;
        int ch;
        while(i<20000000)
        {
                i++;
                ch = pspDebugSioGetchar();
                if((ch >= 0) && (ch != '\r')) {
                        pspDebugScreenPrintf("%c", ch);
                }

        }

        sceKernelExitGame();

        return 0;
}


Makefile:
Code:

TARGET = pspgpslim236
OBJS = main.o

USE_PSPSDK_LIBC = 1

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = GPSlim236

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

LIBS += -lpsphprm_driver
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Mon Jul 24, 2006 8:08 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Mon Jul 24, 2006 2:29 pm    Post subject: Reply with quote

FYI,

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



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 ):
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Jul 24, 2006 3:08 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Thu Jul 27, 2006 3:40 am    Post subject: Reply with quote

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:

static SceUID g_eventflag = -1;


static int intr_handler(void *arg)
{
        u32 stat;

        /* Read out the interrupt state and clear it */
        stat = _lw(0xBE500040);
        _sw(stat, 0xBE500044);

        sceKernelDisableIntr(PSP_HPREMOTE_INT);

        sceKernelSetEventFlag(g_eventflag, EVENT_SIO);

        return -1;
}




int sioReadChar(void)
{
        int ch;
        u32 result;

        ch = pspDebugSioGetchar();
        if(ch == -1)
        {
                sceKernelEnableIntr(PSP_HPREMOTE_INT);
                sceKernelWaitEventFlag(g_eventflag, EVENT_SIO, 0x21, &result, NULL);

                ch = pspDebugSioGetchar();
        }

        return ch;
}

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

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


.................
while (1) {

ch = sioReadChar();
//do something with it...

}
}



[edit] Just realized that the call to ceKernelRegisterIntrHandler returns some huge negative number instead of 0..
hmmm....
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Thu Jul 27, 2006 6:46 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
futaris



Joined: 28 Dec 2005
Posts: 45

PostPosted: Thu Jul 27, 2006 6:48 am    Post subject: Reply with quote

Probably more than likely the remote control handler is still there, until you call sceHprmEnd();
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Thu Jul 27, 2006 2:54 pm    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
Charles



Joined: 28 Jul 2006
Posts: 11
Location: SC

PostPosted: Fri Jul 28, 2006 5:20 am    Post subject: 4800 8N1 Reply with quote

The software that you (deniska) wrote, will it work with NMEA sentences @ 4800 baud?
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Jul 28, 2006 5:36 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Sat Jul 29, 2006 12:19 pm    Post subject: Reply with quote

TyRaNiD, thanks...
I tried the "dirty way" and it worked fine...
Back to top
View user's profile Send private message
Warren



Joined: 24 Jan 2004
Posts: 173
Location: San Diego, CA

PostPosted: Wed Aug 02, 2006 5:52 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Wed Aug 02, 2006 6:01 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Thu Aug 10, 2006 4:22 am    Post subject: Reply with quote

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:
sceGuTexImage( 0, img->textureWidth, img->textureHeight, img->textureWidth, img->data );

        sceGumDrawArray( GU_TRIANGLE_STRIP,  GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, quad );


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....
Back to top
View user's profile Send private message
danzel



Joined: 04 Nov 2005
Posts: 182

PostPosted: Thu Aug 10, 2006 7:15 am    Post subject: Reply with quote

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

Code:
//   sceGuDepthFunc( GU_GEQUAL );
//   sceGuEnable( GU_DEPTH_TEST );


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 :))
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Fri Aug 11, 2006 12:00 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
deniska



Joined: 17 Oct 2005
Posts: 71
Location: New York

PostPosted: Fri Aug 11, 2006 12:05 am    Post subject: Re: 4800 8N1 Reply with quote

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..
Back to top
View user's profile Send private message
Namlas



Joined: 15 Aug 2006
Posts: 2

PostPosted: Sun Aug 20, 2006 7:20 am    Post subject: a Keybord to interface sony's firware using the remote port Reply with quote

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?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group