2014-04-23 05:08 AM
Hi
I am doing a simple thing in C basically witing it to the PORT I register short int a[1] = {1,0}; short int *p = &a; while(1) { GPIOI->ODR |= *p; } Basically fetching data from memory and writing it to the PORT I . I have to write a very long array but for easier understanding, I have used small array. I thought it should take a less clock cycle like 4 max 5 but it is taking so much how can i reduce the clock cycles ...for just writing also it is taking so much clock cycles . what should i do to lessen it The disassembly for his instruction is 74 GPIOI->ODR |= *p; 0800042c: mov.w r3, #8192 ; 0x2000 08000430: movt r3, #16386 ; 0x4002 08000434: mov.w r2, #8192 ; 0x2000 08000438: movt r2, #16386 ; 0x4002 0800043c: ldr r1, [r2, #20] 0800043e: movw r2, #56 ; 0x38 08000442: movt r2, #8192 ; 0x2000 08000446: ldr r2, [r2, #0] 08000448: ldrh r2, [r2, #0] 0800044a: sxth r2, r2 0800044c: orrs r2, r1 0800044e: str r2, [r3, #20] 82 }2014-04-23 05:33 AM
1. switch on optimization in your compiler
2. use DMA 3. use assembler Are you sure you want to OR the data with the port? JW2014-04-23 07:11 AM
Yes I didn't get can you show me any examples
2014-04-23 07:17 AM
Yes, definitely don't want to be using OR, or any RMW instruction, if you want to drive specific bit patterns instead of the entire port bank then consider using the BSRR.
I think there have been other threads, with examples, where this kind of thing has been done with assembler and DMA.2014-04-24 11:38 PM
Thanks Clive it works ........