hi everybody.. I am new in the Embedded programming .. i am writting the keyboard driver for microprocessor.. the status of UART tells me if any data (from keyboard) received or not from the flag register the flag register is of 32 bit ...
1) How can i check the pericular bit in this register set or not?
2) the receiver buffer is of 32 bit but data from keyboard comes in
8bit format.. How can i seperate the 8bit from 32 bit receiver buffer?
well the processor is ARM 7 core based processor. i am using c for coding. well i want to connect the processor with the keyboard using the RS232 protocol. as the keyboard i am using is not a normal key board it is pocket keyboard CE-KB1 (usually used with Zaurus pocket (MI-110M)) after the receiving of data(i.e keycode) the flag bits in the UART get changed i used the "Shift and mask" technique as per your advice its working Thanks for ur help..
I normally use a bit mask such as if you want to look at bit 2 (0100b or 4h) then bitwise AND the flag register with the bit's number - i.e if (FlagRegister & 0x04) {. Since you are working with a UART remember that doing this on the data register counts as a read and will (normally) pop the value off the top of a FIFO, if you are using one.
Which microcontroller is this specifically - you mentioned it was ARM7? I think you'll probably find that only the lower eight bits of the 32bit word contain recieved data. If the UART is anything like the Sharp one I've worked with (and some others) then bits 8, 9, 10 and 11 will contain error flags too.
So, to (possibly) answer both your questions I would try something like:
unsigned char RxCharacter; unsigned int DataWord;
// Pointers to UART registers - likely to be different on your system. unsigned int *DataReg = 0xFFFC0000; //Pointer to data register. unsigned int *FlagRegister = 0xFFFC0018; // pointer to flag register
while ((*FlagRegister & 0x10)); // loop until bit 4 of the flag register gets cleared. // On my uart this means something has been received. Potentially infinite loops // are BAD though so find a better way - this is just an example.
DataWord = *DataReg; // Read the data register (may pop a FIFO)
if (DataWord & 0x0F00) { // check if any of the error bits are set - if the UART supports this return ERROR; // quit if they are } else { // otherwise store the data RxCharacter = (unsigned char)DataWord; // use a cast to strip off the top 24 bits. }
This will work on a Sharp 79524 ARM7 but your device may be similar.
I am not understanding the source of your confusion. The above code fragment does exactly what it says - it checks to see if the n'th bit as specified in the bit_check variable (where the LSB would be labelled as bit 0) is set or clear.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.