Hi Rikard, Rikard Bosnjakovic wrote: > On 02/04/2008, Dario Greggio wrote: > > [...] > >> Probably the "3 Reads" method takes less code and is reliable enough >> once the platform is known. >> > > It's working now. I have not pin-pointed the error, but after setting > bit 1 of TXSTA the code works. But, another question arrived: > I dont understand: bit 1 of TXSTA (TRMT) is a read-only bit! Maybe you wanted to write "testing"? > void send(char letter) { > TXREG = letter; > while (!TRMT) { > // Delay until sent > } > } > > works fine, but according to Nicola this is a Bad Idea (albeit I have > yet not enough knowledge about the USART-module to tell why) and that > In a general case when you need to use any resource then you must be sure that it is free. Secondly there are no reasons to wait after you have sent a byte! The program flow can go on. > I should have written the function like this: > > void send(char letter) { > while (!TRMT) { > TXREG = letter; > } > } > This also is wrong! You are waiting that the port become free and simultaneously using it! Try this: while (!TRMT) ; TXREG = letter; > > Doublechecking the datasheet regarding this bit and register, Nicola > are certainly right about it - that you have to wait for the the bit > (indicating TSR is empty or not) to be set ("register empty") _prior_ > to setting TXREG. > > But, this does not work for my circuit. That is, doing it the "wrong" > way makes it works, and doing it the "correct" way makes it not works. > > Now I'm entirely out in the blue and have no clue of what's going on. > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist