Keil Logo Arm Logo

Discussion Forum

Testing binary serial input in µVision4 debugger

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Miloš Rašic
Posted
18-May-2012 16:57 GMT
Toolset
C51
New! Testing binary serial input in µVision4 debugger

I wrote a piece of code which uses small memory model. It compiles to 65 bytes data and 1646 bytes code. I'm using 3 register banks and all 16 bytes of bit addressable memory. My SP is initialized to address 30h. My main only initializes the hardware and goes into busy wait. I use timer interrupts to send output to parallel ports. The system receives 8-bit commands via serial port, and all commands are binary, like machine code.

My problem is that I can't send my commands to serial port in the debugger in µVision4. The serial window allows me to type to the serial port, but most of my commands do not map to typable characters in ASCII table. The serial tool allows me to trigger and interrupt by setting either RI or TI, but I can't set the contents of the buffer for receive interrupt.

The solution I came up with is to put a breakpoint in the serial interrupt routine, just after the contents of the buffer are read, and use watch window to set the variable into which it is read to the value of my desired command. However, my code is behaving erratically when I do this and I'm not sure whether this is because of the way I'm testing or some other error I've made. It works fine when I don't trigger any serial interrupt. Also, triggering a serial RI interrupt without touching any variables in watch window works without problems: the system receives and executes the 0x00 command. However, when I change a variable in watch window, it sometimes works as intended and sometimes jumps to a forbidden code memory location filled with zeroes.

Any pointers, either towards more reliable code or more reliable testing, would be much appreciated. Thanks in advance.

Read-Only
Author
Erik Malund
Posted
19-May-2012 22:57 GMT
Toolset
C51
New! assembler or C

My SP is initialized to address 30h.
risky business, where are your variables?

Erik

Read-Only
Author
Miloš Rašic
Posted
19-May-2012 23:01 GMT
Toolset
C51
New! RE: assembler or C

Yeah, quite. As it turns out, the compiler puts global variables and the locals it can't put into registers on the lowest memory addresses it thinks are available, and it doesn't take the location of stack into consideration. The reason for erratic behaviour of my code was the global were writing into stack. After some more additions to the code, ended up initializing SP to 60h.

So, my stability problem has been resolved, but I would still know if it is possible to type in a hex or binary value that would be send to the serial port as a byte.

Read-Only
Author
Erik Malund
Posted
20-May-2012 13:37 GMT
Toolset
C51
New! RE: assembler or C

the linker set the stack automatically after the last variable, why do you fool with it

Read-Only
Author
Miloš Rašic
Posted
20-May-2012 15:32 GMT
Toolset
C51
New! RE: assembler or C

I wasn't aware that the linker takes care of SP. Thanks. I had a leaky array in the first draft of my code so I assumed the problem was in SP initialization.

Read-Only
Author
jameel hak
Posted
20-May-2012 20:31 GMT
Toolset
C51
New! RE: assembler or C

what does sp do?

Read-Only
Author
Miloš Rašic
Posted
20-May-2012 20:35 GMT
Toolset
C51
New! RE: assembler or C

Contains the memory address of the last occupied position on the stack.

Read-Only
Author
jameel hak
Posted
20-May-2012 20:48 GMT
Toolset
C51
New! RE: assembler or C

i understand now. same like the register.

Read-Only
Author
Miloš Rašic
Posted
20-May-2012 20:51 GMT
Toolset
C51
New! RE: assembler or C

Yeah, you import reg51.h and you get a bunch of variables mapped to registers.

Read-Only
Author
jameel hak
Posted
20-May-2012 21:02 GMT
Toolset
C51
New! RE: assembler or C

thx mate. you are ace.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.