cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S001J3 setup for AIN2

Joe Lichatowich
Associate II

This is driving me crazy. First time with this processor. I have AFR2 and NAFR2 set properly for AIN2 operation. I can verify that in the watch window and the disassembly window looks like it is working as expected. If I change the channel to AIN7 I can read the 1.2V internal reference correctly. However, the only thing I read on pin 7 (PC4) is 850 to 900 counts. At 2.5V or 0V on that pin it reads the same. I guess I am not reading the pin correctly, maybe there is something different I have to do to get PC4 on that pin or elsewhere in the setup. Using Cosmic compiler. What is the proper way to get PC4 on pin 7? I assumed when AFR2 was set that did it, but maybe not. Any help is appreciated.

1 REPLY 1
Joe Lichatowich
Associate II

Figured it out. It had to do with the proper sequence to unlock and enable the option byte modification. There are several documents that supposedly explain how to do this, but only one tells the complete story (4.5.3 reference): unlock the data memory then enable the option byte modification, modify, then reverse. And even that is a little obscure as another poster wrote here a while ago describing the whole sequence. The section on option bytes doesn't really do a good job of indicating that this has to be done, again not very obvious. You have to look in other sections to find this out.