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 

LUA Serial terminal success

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 13, 2005 12:33 am    Post subject: LUA Serial terminal success Reply with quote

Hi Guys,
I have made what I beleive to be a suitable interface for the PSP serial
port with a pic 16F84A running at 4MHz producing serial data at 2400 baud.

I have altered the serial terminal application to make it run faster by
removing the echo, and removing the check for 60th cycle (produces the
dots on the screen to tell you the program is still running).


Code:

terminal = Image.createEmpty(480, 272)

function scroll(image, dx, dy)
   new = Image.createEmpty(image:width(), image:height())
   new:blit(dx, dy, image)
   return new
end

function printTerminal(text)
   for i = 1, string.len(text) do
      char = string.sub(text, i, i)
      if char == "\n" then
         terminalY = terminalY + 1
         terminalX = 0
      else
         terminal:print(terminalX * 8, terminalY * 8, char, green)
         terminalX = terminalX + 1
         if terminalX >= 60 then
            terminalX = 0
            terminalY = terminalY + 1
         end
      end
      if terminalY >= 34 then
         terminalY = 33
         terminal = scroll(terminal, 0, -8)
      end
   end
end

function normalizeLinefeed(text)
   -- terminal programs like Hyperterminal sends just a \r for return key, convert it
   result = ""
   for i = 1, string.len(text) do
      char = string.sub(text, i, i)
      if char == "\r" then char = "\n" end
      result = result .. char
   end
   return result
end

printTerminal("initializing SIO...\n");
System.sioInit(2400)
infoString = "Rx @ 2400...\n"
printTerminal(infoString);
System.sioWrite(infoString)
ping = 0
while true do
   text = normalizeLinefeed(System.sioRead())
   printTerminal(text)
   screen:blit(0, 0, terminal, 0, 0, terminal:width(), terminal:height(), false)
   screen.waitVblankStart()
   screen:flip()
   if Controls.read():start() then
break
end
end


The terminal is very slow. Even this version requires 15ms character
pacing (that's a full 15 milliseconds between each received character).
I beleive I can make a pic interface between a GPS mouse and the PSP,
receiving at 4800 baud, adding the character pacing, and retransmitting
to the PSP at 2400 baud.
An application like a GPS front end isn't going to have much time to
update the screen to get back to the serial routine for the next seconds
data. There might be the possibility of just updating the data every couple
of seconds.
Cheers, Art.
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 13, 2005 7:18 am    Post subject: Reply with quote

and of course, the code for the pic 16F84A that is to be clocked at 4MHz to
achieve 2400 baud with 15ms character pacing.
The program is compiled with Microengineering Labs Pic BASIC Pro,
and outputs infinite test messages:
" Variable = 0 Variable = 1 Variable = 3.... and so on"
This is what I have reliably achieved on the PSP screen.

The pic program can also drive a 3x7 segment LED display array so you
can view the test variable on LED screen, but it isn't required that any
displays be connected.

Connect the blue wire from your PSP remote controller plug to gnd of the pic circuit,
and the grey wire from the PSP remote via 470 Ohm resistor to port RB0 of the pic circuit
Code:

'
''''''''''''''''''''''''''''''''''''''''''''''
' Multiplexed 3x7 Segment LED Display Driver / PSP Serial port tester '
'                                            '
'         Art           '
''''''''''''''''''''''''''''''''''''''''''''''
'
trisa = 0            'set all ports as outputs
trisb = 0            '
trisa.0 = 1            'now set individual inputs
trisa.4 = 1            '
trisb.0 = 1            '
'
OPTION_REG = %00100000         'put timer module in counting mode
'
include "modedefs.bas"
DEFINE CHAR_PACING 15000         '
'
delay var byte            '
D1 var byte            'display buffers
D2 var byte            '
D3 var byte            '
DB var byte            'display digit buffer
B1 var byte            '
B2 var byte            '
B3 var byte            '
B4 var byte            '
B5 var byte            '
B6 var byte            '
B7 var byte            '
B8 var byte            '
B9 var byte            '
B0 var byte            '
C2 var word            '
M1 var word
'
M1 = 0
@ goto _testA            'skip interrupt handler
'
cnt:
'
Three_dig:
'

DB = D1
low porta.2
gosub digit
high porta.2
DB = D2
low porta.3
gosub digit
high porta.3
DB = D3
low porta.1
gosub digit
high porta.1
return
'
digit:
@            MOVF    _DB      , W
@            SUBLW   0x00
@            BTFSS   STATUS    , Z
@            GOTO    _Label_0016
@            MOVLW   0x80
@            MOVWF   _DB
Label_0016:
@            MOVF    _DB      , W
@            SUBLW   0x01
@            BTFSS   STATUS    , Z
@            GOTO    _Label_0017
@            MOVLW   0xE6
@            MOVWF   _DB
Label_0017:
@            MOVF    _DB      , W
@            SUBLW   0x02
@            BTFSS   STATUS    , Z
@            GOTO    _Label_0018
@            MOVLW   0x48
@            MOVWF   _DB
Label_0018:
@            MOVF    _DB      , W
@            SUBLW   0x03
@            BTFSS   STATUS    , Z
@            GOTO    _Label_0019
@            MOVLW   0x42
@            MOVWF   _DB
Label_0019:
@            MOVF    _DB      , W
@            SUBLW   0x04
@            BTFSS   STATUS    , Z
@            GOTO    _Label_001A
@            MOVLW   0x26
@            MOVWF   _DB
Label_001A:
@            MOVF    _DB      , W
@            SUBLW   0x05
@            BTFSS   STATUS    , Z
@            GOTO    _Label_001B
@            MOVLW   0x12
@            MOVWF   _DB
Label_001B:
@            MOVF    _DB      , W
@            SUBLW   0x06
@            BTFSS   STATUS    , Z
@            GOTO    _Label_001C
@            MOVLW   0x10
@            MOVWF   _DB
Label_001C:
@            MOVF    _DB      , W
@            SUBLW   0x07
@            BTFSS   STATUS    , Z
@            GOTO    _Label_001D
@            MOVLW   0xC6
@            MOVWF   _DB
Label_001D:
@            MOVF    _DB      , W
@            SUBLW   0x08
@            BTFSS   STATUS    , Z
@            GOTO    _Label_001E
@            CLRF    _DB
Label_001E:
@            MOVF    _DB      , W
@            SUBLW   0x09
@            BTFSS   STATUS    , Z
@            GOTO    _Label_001F
@            MOVLW   0x02
@            MOVWF   _DB
Label_001F:
portb = DB
'
pauseus 2200
portb = $FF
'
'

'
return
'
'***************************************************************************************************************
'
testA:
delay = 5
C2 = 0
'
test:
low porta.2
gosub segments
high porta.2
low porta.3
gosub segments
high porta.3
low porta.1
gosub segments
high porta.1
low porta.4
gosub segments
high porta.4
delay = delay - 1
IF delay = 255 THEN
INTCON = %10010000         'turn on interrupt when display test is done
goto start
ENDIF
goto test
segments:
high portb.1
pause delay
high portb.2
pause delay
high portb.3
pause delay
high portb.4
pause delay
high portb.5
pause delay
high portb.6
pause delay
high portb.7
pause delay
low portb.1
pause delay
low portb.2
pause delay
low portb.3
pause delay
low portb.4
pause delay
low portb.5
pause delay
low portb.6
pause delay
low portb.7
pause delay
return
'
'***************************************************************************************************************
'
start:
D1 = 0
D2 = 0
D3 = 0
'
FOR delay = 0 TO 90         'Hold 000 on display at startup
gosub Three_dig
NEXT delay
'goto cnt
'
'***************************************************************************************************************
'

Dog:

M1 = M1 + 1

D1 = M1 DIG 0            '
D2 = M1 DIG 1            '
D3 = M1 DIG 2            '

FOR delay = 0 TO 75         'Hold display
gosub Three_dig
NEXT delay


serout portb.0,OT2400,[" Variable = ",#M1]    ' 2400 baud true

goto Dog            '


disp:
D1 = C2 DIG 0            '
D2 = C2 DIG 1            '
D3 = C2 DIG 2            '

FOR delay = 0 TO 100         'Hold display
gosub Three_dig
NEXT delay
return


And here's the hex code so you don't need to own the compiler to test the circuit:
Code:

:10000000AC28910190009F1727308F0010301420EA
:1000100003308F00E83014208F01643014208F01EA
:100020000A30142010081F288E0011088D001008B7
:100030008C008B200C08031D9F139F1B0800303E73
:100040009200220884000930930003103020920CA3
:10005000930B2628031430203A308D0098306D28F9
:1000600084139F1D3F28000820041F1D20068000C8
:10007000841700082004031C200680004A2800087A
:100080002004031C20061F19200680008417200965
:1000900080054A281F0D06398C0053208D008C0ADC
:1000A000532000006D2800308A000C0882070134BC
:1000B00075340334153400343C340C34D9348F0196
:1000C0008E00FF308E07031C8F07031CA728033008
:1000D0008D00DF306D2061288D01E83E8C008D0998
:1000E000FC30031C76288C07031873288C076400E7
:1000F0008D0F73280C187C288C1C80280000802809
:100100000800013E93000A308E008F018B20930B74
:1001100086281008080091019001103092000D0D02
:10012000900D910D0E0890020F08031C0F0F910205
:100130000318A1280E0890070F0803180F0F910746
:1001400003108C0D8D0D920B8F280C08A72883139C
:1001500003138312640008008316850186010514C9
:1001600005160614203081008312A601A7011E295E
:100170003208B5000511831605118312DA20051522
:100180008316051183123308B50085118316851176
:100190008312DA2085158316851183123408B50081
:1001A0008510831685108312DA2085148316851036
:1001B000831208003508003C031DE0288030B5009C
:1001C0003508013C031DE628E630B5003508023C41
:1001D000031DEC284830B5003508033C031DF22808
:1001E0004230B5003508043C031DF8282630B50020
:1001F0003508053C031DFE281230B5003508063CC5
:10020000031D04291030B5003508073C031D0A29D9
:10021000C630B5003508083C031D0F29B501350867
:10022000093C031D15290230B50035088600083049
:100230008D0098306D20FF30860008000530B60034
:10024000A401A5010511831605118312502105157E
:10025000831605118312851183168511831250218F
:1002600085158316851183128510831685108312D8
:1002700050218514831685108312051283160512EA
:10028000831250210516831605128312B6036400EB
:100290003608FF3C031D4F2990308B00A5292229E9
:1002A000861483168610831236085F20061583167F
:1002B0000611831236085F20861583168611831275
:1002C00036085F20061683160612831236085F2052
:1002D000861683168612831236085F200617831649
:1002E0000613831236085F2086178316861383123F
:1002F00036085F20861083168610831236085F202A
:10030000061183160611831236085F2086118316A4
:100310008611831236085F20061283160612831296
:1003200036085F20861283168612831236085F20F5
:10033000061383160613831236085F20861383166E
:100340008613831236085F200800B201B301B4019E
:10035000B60164005B3036020318B129B820B60F2D
:10036000A929A60A0319A70A26088C0027088D00C8
:1003700000308120B20026088C0027088D00013053
:100380008120B30026088C0027088D0002308120D0
:10039000B400B60164004C3036020318D229B820EC
:1003A000B60FCA290630A2000130A00008309F0015
:1003B0002030202056302020613020207230202034
:1003C0006930202061302020623020206C302020D5
:1003D00065302020203020203D302020203020207B
:1003E0002708910026080220B12924088C0025083E
:1003F0008D0000308120B20024088C0025088D007B
:1004000001308120B30024088C0025088D000230C3
:100410008120B400B6016400653036020318132A47
:08042000B820B60F0B2A0800FA
:02400E00F53F7C
:00000001FF

I am releasing this because I intend to take it further.
I will shortly biuld a smaller circuit without the display
for the purpose of serial level/timing conversion between the
PSP and other devices (particularly GPS).
Cheers, Art.



Cheers, Art.
Back to top
View user's profile Send private message
Master Inuyasha



Joined: 13 Nov 2005
Posts: 13

PostPosted: Sun Nov 13, 2005 9:58 am    Post subject: Reply with quote

what is the point of this?
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 13, 2005 10:05 am    Post subject: Reply with quote

In the long run, hopefully a way to get data from a GPS mouse into the PSP
so myself or someone else can get started on a GPS front end.
I hope to get a moving 'Google Earth image' compatible GPS up & running.

If you have no way of programming a pic, and putting it into a suitable
circuit, this isn't for you.
Art.
Back to top
View user's profile Send private message
Master Inuyasha



Joined: 13 Nov 2005
Posts: 13

PostPosted: Sun Nov 13, 2005 10:24 am    Post subject: Reply with quote

oh know i see, i never knew you could do that on the PSP. Way to go!!! Good luck.
Back to top
View user's profile Send private message
Zenurb



Joined: 30 Sep 2005
Posts: 106
Location: United Kingdom

PostPosted: Sun Nov 13, 2005 10:56 am    Post subject: Reply with quote

I'm interested in this, but I've got no hardware available to me, being as I am a poor student :P

Perhaps you could post circuit diagrams / lists of equipment you used to help other people in future.
_________________
Proud Dvorak User
US 1.5 PSP (Original)
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Mon Nov 14, 2005 8:11 am    Post subject: Reply with quote

It doesn't look to be possible to post pictures here.
I would probably like to wait till I have something more developed.

After some more testing with the serial terminal program, I don't think it's
ever going to be fast ehought to receive data directly from a GPS mouse
even at 4800 baud without a chip in between to buffer and retransmit the
signal at slower rates.

I might even look at some 'pre-processing' of the GPS data so that only
minimal bytes need be send to the PSP.
Art.
Back to top
View user's profile Send private message
JoshDB



Joined: 05 Oct 2005
Posts: 87

PostPosted: Mon Nov 14, 2005 8:18 am    Post subject: Reply with quote

If you could develop a keyboard for the psp...

Good god man, you'd be loved.
Back to top
View user's profile Send private message Send e-mail AIM Address
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Mon Nov 14, 2005 9:23 am    Post subject: Reply with quote

a serial keyboard would be very simple to make, but a DIY one
might not look pretty.
People would need to biuld the hardware themselves,
and write PSP software to support it.
I'm not sure it would catch on being a hardware project.

I have a good schematic drawing for the circuit described above.
Does anyone have somewhere to host it (and another image).
and perhaps possible future hardware projects?
Cheers, Art.
Back to top
View user's profile Send private message
aldebaran



Joined: 17 Nov 2005
Posts: 12

PostPosted: Thu Nov 24, 2005 7:04 pm    Post subject: Reply with quote

Can you post me the drawings of your rs 232 interface? I'll try to develop a serial keyboard, too. Thanks.
Back to top
View user's profile Send private message
JoshDB



Joined: 05 Oct 2005
Posts: 87

PostPosted: Fri Nov 25, 2005 1:41 am    Post subject: Reply with quote

I have unlimited space/bandwidth on my server.

Anything you want, just PM me.
Back to top
View user's profile Send private message Send e-mail AIM Address
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 27, 2005 4:38 am    Post subject: Reply with quote

Quote:
If you could develop a keyboard for the psp...

Good god man, you'd be loved.

Quote:
I'll try to develop a serial keyboard, too. Thanks.

With the new IRDA support in LUAplayer, it won't be long before someone
is using an IRDA keyboard for mobile phones with the PSP.
I don't think there would be any stuffing around with hardware involved at all.

My GPS front end program is hosted at a couple of sites now, and linked
to from a couple more, so no need to have it hosted again, and try to
update them all at once when I have new versions to upload.
Art.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Nov 27, 2005 12:43 pm    Post subject: Reply with quote

Art wrote:
After some more testing with the serial terminal program, I don't think it's
ever going to be fast ehought to receive data directly from a GPS mouse
even at 4800 baud without a chip in between to buffer and retransmit the
signal at slower rates.


Thanks for discovering this problem, looks like Lua Player sucks :-)

The reason is that the SIO data is not buffered in some large system buffer, as I wrongly assumed in some other posting, but only the hardware FIFO is used. I don't know the size of it, but normally it is something like 8 or 16 bytes. So if you query only every 1/60 seconds (every vsync), you read the buffer every 16 ms, but at 4800 baud the hardware receives about 10 bytes in 16 ms, which might be too much for the hardware buffer.

A (bad) solution would be to use System.sleep and polling instead of using vsync. A better solution would be to improve the Lua Player SIO driver to use interrupt based reading (if possible by the hardware) with larger buffers and synchronized access.
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 Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
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