ComputerNerd / ov7670-no-ram-arduino-uno

Allows you to use a non fifo ov7670 on the arudino uno without external spi ram like other examples. Sends the data to UART.
237 stars 111 forks source link

Main.c does cli() but not sei() #8

Open abbanerjeersm opened 9 years ago

abbanerjeersm commented 9 years ago

Hi - can you please explain why the main.c code just uses a cli to clear interrupts but is not neccesary to use a sei() once setting up the timing registers ?

ComputerNerd commented 9 years ago

My code never uses interrupts.

abbanerjeersm commented 9 years ago

So why are you clearning the interrupts with cli() ?

abbanerjeersm commented 9 years ago

Found the answer in the datasheet of Atmega 328p - page 175

For interrupt driven USART operation, the Global Interrupt Flag should be cleared (and interrupts globally disabled) when doing the initialization. Before doing a re-initialization with changed baud rate or frame format, be sure that there are no ongoing transmissions during the period the registers are changed. The TXCn Flag can be used to check that the Transmitter has completed all transfers, and the RXC Flag can be used to check that there are no unread data in the receive buffer. Note that the TXCn Flag must be cleared before each transmission (before UDRn is written) if it is used for this purpose.