Question
Option bytes complementary error with manual write
Hello.
I'm trying to set Option bytes on STM8s005k6 from main code, but still I'm getting error in complementary bytes (when I try to rad out it back in STVP) and MCU hangs.
I'm using SDCC compiler with this code:
// Set option bytes because of buzzer
if(OPT->OPT2 != 0x80 || OPT->OPT3 != 0x08){
FLASH->CR2 |= FLASH_CR2_OPT; //unlock option bytes for writing
FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NOPT);
while (!(FLASH->IAPSR & FLASH_IAPSR_DUL));
OPT->OPT2 = 0x80; // enable LSI clock source
OPT->NOPT2 = 0x7f;
OPT->OPT3 = 0x08; // set PD4 as alternative buzzer output
OPT->NOPT3 = 0xf7;
while (!(FLASH->IAPSR & FLASH_IAPSR_EOP)); // wait for write finish
FLASH->CR2 &= (uint8_t)(~FLASH_CR2_OPT); //lock back
FLASH->NCR2 |= FLASH_NCR2_NOPT;
}If I set it through graphic STVP and read OPT2 and OPT3 registers, they have exactly these values. But from code it doesn't accept :\
Thank you for any tips.
