2015-12-29 06:12 PM
Would someone assist with the logic of my 4 stage if-statement. It basically performs one of four groups depending upon how 2 dip switches are set. The problem is that no matter how I set the 2 dip switches it always goes to line 868 (see attachment). I can never get it to go to line 859, 862, or 865, no matter how I set the external dip switches. I have monitored the dip switches and they are functioning properly as a 3.3V or 0V logic level, depending upon dip position. Dip 1 interfaces to PA2, and dip 2 interfaces to PC5.
Maybe I don't have my parenthesis set correct, or maybe my center & needs to be &&? Perhaps my ! is not the correct operand? I even tried a different approach as per line 839-855, but that didn't work AT ALL, i.e., after setting breakpoints at 841,845,850,or 854, it never stopped.2015-01-03 05:00 PM
Hello Ian,
Thanks for your response. I have initialized PA2 and PC5 per line157_ See attachment. Contact bounce is not possible because I only set them when the program is notrunning. I changed & to &&. No matter what the dip switch settings, the program still always stops at line8 See attachment. I have the dip switch high line attached to3.3V and the other to the IO. Last time I implemented this in ST72F264 Iused some pull down resistors too some years ago without these kinds ofproblems, but when I measure the voltage at the IO it is either 3.3V oressentially ground. I even tried adding code shown at line 854_855_857, but it doesn't help so Icomment it out. Would you show me the code that will implement: ''GPIOx statementswith variables, one per switch and then use the debugger to set the variablesto 0 and 1 (in the correct bit position).'' However, I am doing a lot with the STM8L: RTC, 2 comparators, internalref, I2C, SPI, lots of IO's as outputs (high and low), no LCD, but I don't seehow PA2 and PC5 can possibly be conflicting with something else. ________________ Attachments : PA2_PC5_Initialized_As_Input_in_Main_Line_157_158.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzO4&d=%2Fa%2F0X0000000bKx%2FzX6r2S5aExsrFrVoFkFwurKHa4JVDUCWj8HjmuycIJ4&asPdf=false2015-01-03 05:03 PM
Hello Ian,
Thanks for your response. I have initialized PA2 and PC5 per line157_ See attachment. Contact bounce is not possible because I only set them when the program is notrunning. I changed & to &&. No matter what the dip switch settings, the program still always stops at line8 See attachment. I have the dip switch high line attached to3.3V and the other to the IO. Last time I implemented this in ST72F264 Iused some pull down resistors too some years ago without these kinds ofproblems, but when I measure the voltage at the IO it is either 3.3V oressentially ground. I even tried adding code shown at line 854_855_857, but it doesn't help so Icomment it out. Would you show me the code that will implement: ''GPIOx statementswith variables, one per switch and then use the debugger to set the variablesto 0 and 1 (in the correct bit position).'' However, I am doing a lot with the STM8L: RTC, 2 comparators, internalref, I2C, SPI, lots of IO's as outputs (high and low), no LCD, but I don't seehow PA2 and PC5 can possibly be conflicting with something else. ________________ Attachments : If_Statement_nn.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hyeh&d=%2Fa%2F0X0000000bKw%2F.McEWWmsv7kJuzAuV_iK9wYOJgPGHo1p8f07AheNEtk&asPdf=falsePA2_PC5_Initialized_As_Input_in_Main_Line_157_158.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzNu&d=%2Fa%2F0X0000000bKy%2FZX8PFnNbY4dkrG9EV2bL9D7JBMHo7BQMz4JrDDqfHWU&asPdf=false2015-01-05 01:08 AM
Hello,
Yes it looks like PC5/PA2 are initialised correctly but it might be worth configuring for the weak pull-ups or downs, just to fully define 0 and 1 etc. It appears that the right levels are appearing on the pin side of the chip but not internally! It would be worth just checking that PC5/PA2 don't conflict with other peripherals or have alternative mappings etc. Might also be worth trying with different known working port pins. For debugging my idea to use variables is simply to check the ''if'' code as opposed to the hardware. The idea is to replace the occurrences of GPIOx->IDR with say myPORTA defined as a byte or unsigned char. Then in the debugger you can set myPORTA as 0x4 to represent pin PA2. Your ''if'' logic might also need to be explicit on the conditions, thus: if (((GPIOA->IDR & 4) == 1) && ... etc Hope that helps. Thanks, Ian2015-01-05 11:42 PM
I shared a post just now. Did you get it? I don't see it. ST's system is frustrating me: You'll see I have a double post from two days ago because it doesn't instantly show a post or logs you out when you are working on a response, without telling you. My very first experience a few weeks ago, I posted twice because of this issue. Now I'm too tired to work on this any longer tonight and frustrated!!!
2015-01-06 01:01 AM
Hello,
No sorry I can't see a shared post from you but I have to agree that ST's forums system is quite poor compared to say Freescales version! There isn't even enough room to view the message one is trying to reply to!! Ian2015-01-06 10:56 PM
Hello Ian, I tried weak pull downs and they didn’t help. I checked an old schematic and weak pull downs is what was done when using the ST72F264.
PC5/PA2 potential alternative/peripheral conflicts: I checked, but I don’t think that’s the issue. The pins and alternates are defined accordingly:
PA2/OSC_IN/USART1_TX/SPI1_MISO
PC5/OSC32_IN/SPI1_NSS/USART1_TX
We use all internal oscillators (LSI,HSI,and for RTC -internal 32kHz)
We don’t use USART.
We use SPI1, but through PB5(SCK),PB6(MOSI), PB4(Enable),
The one interesting thing is that with SPI initialization, we do use a parameter called SPI_NSS_Soft, and we also have some commands using SYSCFG for analog routing at analog switch 1 and 14, and a command for I/O switch to connect PC7 to Comparator 1. However, the
SYSCFG_RMPCR1
couldn’t be getting reconfigured or PB5,PB6, PB4 would not be working perfectly for us.2015-01-07 12:40 AM
Hello,
Have you been able to try the if code with different known working GPIO pins or with the variable version of the GPIO registers? There might be a possible conflict with the SPI1_NSS pin PC5 but if you're setting bit SMM in the SPI_CR2 register then it's not an issue? Ian2015-12-30 12:43 AM
Hello,
Have you got PA2 and PC5 set as an input? I'm firstly wondering if you are getting contact bounce if you are changing the dip switches on the fly while the program is running? Secondly the middle & does indeed need to be && (bit wise and logical AND operators respectively). Your use of brackets and ! is fine. Another way to test your logic is to replace the GPIOx statements with variables, one per switch and then use the debugger to set the variables to 0 and 1 (in the correct bit position). Hope that helps. Ian