your help please, this pointer initially takes the first value extracted from the address, but when I try to increase the pointer to access the next value it does not do anything.(ARM7TDMI LPC2136):
void static commandList(const uint8_t *addr) {
uint8_t numCommands, numArgs; uint16_t ms;
numCommands = *(addr++); // Number of commands to follow while(numCommands--) { // For each command... writecommand((uint8_t) *(addr++)); // Read, issue command numArgs = *(addr++); // Number of args to follow ms = numArgs & DELAY; // If hibit set, delay follows args numArgs &= ~DELAY; // Mask out delay bit while(numArgs--) { // For each argument... writedata(*(addr++)); // Read, issue argument }
Delay(ms);
}
Please read the posting instructions for source code, otherwise it is just unreadable.
If you don't understand the problem
Use a debugger to step through it Review the code generated by the compiler Instrument the code so understand *what* is happening
For the hard-of-reading, here is a picture to help you:
www.danlhenry.com/.../keil_code.png
This is the array that receives the function through the pointer. in the first instruction it correctly receives the data of the first position but from the second increment of address it does not change and the data is not extracted.
static const uint8_t Rcmd1[] = { // Init for 7735R, part 1 (red or green tab) 15, // 15 commands in list: ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay 150, // 150 ms delay ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay 255, // 500 ms delay ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args: 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args: 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args: 0x01, 0x2C, 0x2D, // Dot inversion mode 0x01, 0x2C, 0x2D, // Line inversion mode ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay: 0x07, // No inversion ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay: 0xA2, 0x02, // -4.6V 0x84, // AUTO mode ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay: 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay: 0x0A, // Opamp current small 0x00, // Boost frequency ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay: 0x8A, // BCLK/2, Opamp current small & Medium low 0x2A, ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay: 0x8A, 0xEE, ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay: 0x0E, ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg: 0xC8, // row addr/col addr, bottom to top refresh ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay: 0x05 };
void static commandList(const uint8_t *addr) { uint8_t numCommands, numArgs; uint16_t ms; numCommands = *(addr++); // This value is recieved correct while(numCommands--) { // For each command... writecommand(*(addr++)); // Read, issue the pointer not increment correctly numArgs = *(addr++); // Number of args to follow ms = numArgs & DELAY; // If hibit set, delay follows args numArgs &= ~DELAY; // Mask out delay bit while(numArgs--) { // For each argument... writedata(*(addr++)); // Read, issue argument } Delay(); } }
commandList(Rcmd1); //this is the called
this instruction is fine: numCommands = *(addr++); after these instructions the pointer does not increase: writecommand(*(addr++));
Your indentation is a bit messed-up.
void static commandList(const uint8_t *addr) { uint8_t numCommands, numArgs; uint16_t ms; numCommands = *(addr++); // This value is recieved correct while(numCommands--) { // For each command... writecommand( *(addr++) ); // Read, issue the pointer not increment correctly numArgs = *(addr++); // Number of args to follow ms = numArgs & DELAY; // If hibit set, delay follows args numArgs &= ~DELAY; // Mask out delay bit while(numArgs--) { // For each argument... writedata( *(addr++) ); // Read, issue argument } Delay(); } }
"the pointer does not increase"
But does writecommand() actually receive the correct value?
And does numArgs get set to the correct value?
Instrument your code with printf() to understand what happening in the loop and in the writedata() function.
Variables may be held in registers, not memory
As I said earlier the instruction * (addr ++) is not working.
No, it is not taking the values. will take the value zero at all times.
I have run the program step by step but I did not identify the reason of the problem. if you are interested I can take screenshots with the assembler code.
Thanks.
void static commandList( const uint8_t *addr )
Is that 'const' in the right place ... ? Yes, it is.
This code if I compile it for the arm cortex of texas Tiva C tm4c123g. works correctly. but when I carry the code and compile for the ARM7tdmi lpc2136 it gives this problem with the pointer. and with the simulation of delays.
Compiled on a PC, generates sequences you're not handling properly
# 15 CMD 11 (17) DELAY CMD 96 (150) DAT 80 . DAT FF . DAT 33 3 DAT 03 . DAT 01 . DAT 2C , DAT 2D - DAT 44 D DAT 03 . DAT 01 . DAT 2C , DAT 2D - DAT 55 U
Took liberties with the missing defines, but still looks broken to me.
>>if you are interested I can take screenshots with the assembler code. A listing file, or FromELF disassembly might be better, but the underlying logic is flawed. Instrument the code, understand what it actually does. Compiler doing what you tell it to do.
after doing several tests remove the "static" modifier from the function and leave it as a normal call. after this I am capturing the values correctly from the pointer.
I must clarify that this function belongs to the library of the TFT LCD 128x160 with the ST7735 driver.
Thank you (Andrew Neil) and the others for your comments!!