This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F28377D - Reading PORTB - Second post now.

Hi Guys, I'm new with the F28377D but very experienced with other microcontrollers.

I have a push button switch connected to PORTB0 GPIO32 and the other side to GND.

I'm trying to read the pin so when you press down on the button the port should read 1

but I can't seem to read the port.  Here my code snippet:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;PORTB
    EALLOW
    MOVL XAR7,#GPBSET   ;WRITE GPBSET FIRST THEN GPBDIR
    MOV AL,#0           ;FOR LATCH.
    MOV AH,#0
    MOVL *XAR7,ACC
    NOP
    MOVL XAR7,#GPBDIR   ;GPIO B DIRECTION REGISTER
    MOV AL,#0x0         ;LOWER 16BITS - ALL OFF FOR INPUT
    MOV AH,#0x0         ;UPPER 16BITS - ALL OFF FOR INPUT
    MOVL *XAR7,ACC      ;STORE IN GPBDIR REGISTER
    MOVL XAR7,#GPBPUD   ;PORTB PULLUPS ON. 0=ON, 1=OFF
    MOV AL,#0x0
    MOV AH,#0x0
    MOVL *XAR7,ACC      ;STORE IN GPADIR REGISTER
    EDIS
;----------------------------------------------------
MORE:
    LC LED_OFF
MORE1:
    IN AL,*(GPBDAT) ;PORT B
    CMP AL,#0x0
    B MORE,EQ
    LC LED_ON
    B MORE1,UNC

What the above code does is sets up PORTB for input, reads PORTB.

If the push button is pressed then PORTB should = 1 and turn on a LED but

it doesn't. Can you please let me know if I am reading the port correctly or is there

other registers I have to set up first.

Thanks guys

Pete

  • Peter,

    Not sure why you are coding in assembly instead of C.  Well, at least one mistake is your use of the 'IN' instructions.  'IN' reads I/O space (vs. program space or data space).  It is a legacy thing, and in fact there is nothing connected to I/O space on any C28x devices.  The GPIO registers are in data space.  You should use a regular MOV instructions to read them.

    Regards,

    David

  • Thanks David for the Reply. I'm not coding in C because I'm not a C programmer, I'm an assembler programmer and have been for over 30 years since the 6502. I also need to count machine cycles for a VGA project and you can't do that C.

    Thanks again for your reply, I'll try out the MOV instruction.

    Pete

  • Pete,

    another Problem in your code is the compare-instruction:

    IN AL,*(GPBDAT) ;PORT B

    CMP AL,#0x0

    After you read the whole port B (with a MOV - instruction, as David pointed out), you will have to mask out all other bits of portB, (AND AL,#1 ) to make sure that only pin B0 will control the next following branch construction (CMP).
     
    Regards
     
    PS: Of course you can count the number of clock cycles also in C (clock profiler in CCS). This tool will also take into account the influence of the instruction Pipeline, which you would have to do manually in ASM.
     
     
     
  • Thanks Frank, really appreciate it. :)

    Pete