can`t read any port?

YT2095
2013-10-14
2013-11-01
1 2 > >> (Page 1 of 2)
  • YT2095

    YT2095 - 2013-10-14

    Iv been having a problem for 3 days now and cant seem to resolve it, I`v tried the most Basic of all programs here:
    dir portc in
    dir portb out

    start:
    portb=portc
    goto start:

    in theory this should output on port b any input on port c, Nada!
    Iv tried it with 2 different Atmel MCUs and also on a PIC chip, stull nothing. I can set the ports to any numeric value and it works, I just cant get that value from another port.
    However Analogue (readAD) command does work!?
    I`v even tried a single Bit of a port and the same thing happens.
    it also seems to assemble just fine too, here:

    ;Start of the main program
    ldi SysValueCopy,0
    out DDRC,SysValueCopy
    ldi SysValueCopy,255
    out DDRB,SysValueCopy
    START:
    in SysValueCopy,PORTC
    out PORTB,SysValueCopy
    rjmp START

    any idea why it`s suddenly started doing this?
    it Used to work just fine before, but Now nothing.

     
  • Rikki

    Rikki - 2013-10-14

    Have you tried setting portC to be an input?

     
  • YT2095

    YT2095 - 2013-10-14

    yup, Iv tried every single possible combination using all ports as either in or out, and over 3 different ICs on 2 different boards in case it was a hardware fault or blown port. even tried adding wait statements betwen each action in case it was too fast and making RF noise. Iv reinstalled my Original version of GCB too and tried that too, and on 2 different laptops.
    everything was fine until I updated my 2010 version of GCB (I needed one of the new libraries) and all seemed to be fine except for this.

     
  • Rikki

    Rikki - 2013-10-14

    As a work around try this code:

    dir portB out
    dir portC in
    wait 5 us ' ensure AVR has sufficient time to change port directions
    my_variable =portC
    portB =my_variable

     
  • YT2095

    YT2095 - 2013-10-14

    still nothing.
    in fact it was something Similar to the above that lead me discover the problem, I was using Delay = portc to set the step rate for a stepper motor.
    if its of any help, the RS232 RX and TX works justs fine, so theres nothing actually Wrong with the chips.

     
  • Anobium

    Anobium - 2013-10-14

    Is this a LAT read\rite issue?

    try... set latc = portc

     
  • YT2095

    YT2095 - 2013-10-14

    currently Im using an Atmega 1284p in there, so its probably stuff like DDR and the likes?
    but yes, it`s certainly a Read issue.

     
  • YT2095

    YT2095 - 2013-10-16

    ok, I tried all the DDR permutations and still the same effect, I even tried using a different uploader for the Hex file that GCB generates, and nothing?
    I have had Partial success with this:

    ;Chip Settings

    chip mega1284p,16

    dir portc out
    dir porta in

    start:

    If porta.0=1 then
    portc=0
    End if
    If porta.0=0 then
    portc=170
    End If

    goto start:

    NB, I use 170 as the output number as its pretty distinctive and unlikely to be confused with anything else, thats all.

    the above Does actually work, but still no way to read an entire ports Value?

     
  • YT2095

    YT2095 - 2013-10-18

    Iv been experimenting Further and still cannot read the value of a whole port!? all Im getting is 0 as a value when a read is tried, I used this code to test with:

    ;Chip Settings

    chip mega1284p,16

    ;Defines (Constants)

    define LCD_IO 8

    define LCD_DATA_PORT portc

    define LCD_RS PORTD.5

    define LCD_RW PORTD.4

    define LCD_Enable PORTD.3

    dir portb in
    dir porta in
    cls
    main:
    cls
    lcdint (portb)
    porta= value
    locate 1,0
    print value
    wait 200 ms
    goto main:

    in effect this just reads the value of ports A and B and displays them on the LCD, both read "0" no matter what input I try (hard GND or +5V).
    so the GCB software is broken somewhere along the line.
    Im using version 9, with all the latest updates unpacked into the correct folders. does GCB call on any Other program outside of itself to upload or parse any data at all? maybe thats whats corrupted? I Seriously need some Help with this as I have Design that needs to be finished at the end of the month and Iv wasted a week on this nonsense already :(
    is anyone Else having a similar problem at all?

     
  • Anobium

    Anobium - 2013-10-18

    Understand frustration. I do not have mega1284p chips but trying to help. Just try the code below.

    ~~~~
    ;Chip Settings

    chip mega1284p,16

    ;Defines (Constants)
    define LCD_IO 8
    define LCD_DATA_PORT portc
    define LCD_RS PORTD.5
    define LCD_RW PORTD.4

    define LCD_Enable PORTD.3

    dir portb in
    dir porta in
    cls
    main:
    cls
    lcdint (portb)
    value = porta
    locate 1,0
    print value
    wait 200 ms
    goto main

     
  • Rikki

    Rikki - 2013-10-18

    Maybe try to approach this by accessing the atmega 2560 port registers

    poke (1,0) 'set all port A pins direction in
    poke (4,0) 'set all port B pins direction in

    ' lcd code here

    MyPortA= peek(0) 'raw read portA input register
    MyPortB= peek(3) 'raw read portB input register

    print MyPortA
    print MyPortB

     
    Last edit: Rikki 2013-10-18
  • YT2095

    YT2095 - 2013-10-18

    4 compile errors...

    error: GCASM: Symbol MEMADR has not been defined
    same with MEMADR_H, MEMDATA and also PEEK.
    the 1284P is my own chipdata, but I`m having the same problem with PIC chips too so I can pretty much rule that out.

    Anobium, your program didnt work either (even after i added the #s for the defines).

     
  • Anobium

    Anobium - 2013-10-18

    Give me one hour. I will do a test compile using my config.

     
    • Anobium

      Anobium - 2013-10-18

      I have compiled with no errors.

      Please attach your chip file. I can only test with my chip files. I chose a 16F1937... not your chipset. :-(

       
  • Rikki

    Rikki - 2013-10-18

    Hi the poke /peek command doesn't like leading zeros.

    I have edited the post to use decimal instead....maybe try to compile your code again

     
  • YT2095

    YT2095 - 2013-10-18

    the 1284P chipfile is attatched.

    I had no problem compiling with Any chipset (PIC or Atmega), only the one that had the "Peek" commands in them,it Should work (and indeed used to work) using any of the code I posted in this thread.

    meanwhile Iv found a pair of laptops that have never had GCB on them before, so Im going to try a 100% fresh instal on one and see how that goes.

     
  • Anobium

    Anobium - 2013-10-18

    Compiles with no errors.

     
  • YT2095

    YT2095 - 2013-11-01

    Iv finally found a workaround after much messing about with code (which I didnt want to do hence I choose to use Basic).

    DDRB = 0XFF
    DDRD = 0X00

    START:
    Test = PIND
    PORTB = Test
    goto START:

    This seems to work perfectly well, but Iv still got no idea why the same in pure Basic wont work though?

    I`v also managed to get a 16F57 chip to work from pure basic, but Only after I read the chip from the PK2 software will the chip actually start to work as programmed.

    Something somewhere is broken.

     
  • Anobium

    Anobium - 2013-11-01

    Check your circuit very carefully. Do you have a decoupler capactitor? Common 0v rails?

     
  • YT2095

    YT2095 - 2013-11-01

    yup, all is perfect h/ware wise, Iv tried many different boards and ICs too. the Problem that I can see so far as Im trying to lock it down, is the PORT command.

    the DIR PORT x In/Out is fine (so no need for the DDRx)

    and if I replace PORTx with PINx all works as it should when trying to Read a port.

    if youre Outputting to a port, then fine, you can use PORTx, but its no good anymore to Read a whole port.

     
  • Anobium

    Anobium - 2013-11-01

    I really sorry but I cannot follow/fully understand the post.

    My summary.
    dir portx in|out works as expected. When you read and write the assigned port respectively.
    dir pinx in|out only works when reading a pin. But, you have issues when reading pins? or do you mean reading a port?

     
  • YT2095

    YT2095 - 2013-11-01

    sorry, my bad.
    yes you can set the port Dir as normal.
    and you can Output to a port as normal too.
    but if you want to Read an entire port you can`t use the Port command, ie;

    Var = PORTD will not work
    instead I have to use;
    var = PIND

     
  • Anobium

    Anobium - 2013-11-01

    Can you post you code please? I am sure you have something here.

     
  • YT2095

    YT2095 - 2013-11-01

    sure, this code works:

     ;Chip Settings
     #chip mega16,4
    
     dir portd in
     dir portb out
    
     start:
     test = PIND
     portb = test
     goto start:
    

    now the Same thing using PORTD does Not work:

     ;Chip Settings
     #chip mega16,4 
    
     dir portd in
     dir portb out
    
     start:
     test = Portd
     portb = test
     goto start:
    

    edited by Anobium to correct code layout.

     
    Last edit: Anobium 2013-11-01
1 2 > >> (Page 1 of 2)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks