Using A/D converter in 802.15.4 MAC SW

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using A/D converter in 802.15.4 MAC SW

1,810 Views
PaoloPinkel
Contributor I
Hello,

I'm using the MC9S08GT60 and I want to transmit data of the ADC from a device to a coordinator in a 802.15.4 network. My actual problem is not the transmitting of the data but the correct use of the ADC.

I want to use PTB2 and so I initialize the registers as follows:
Code:
  ATDPE=0b00000100;  ATDC=0b10100000;  ATDSC=0b00100010;  test=ATDRH;


So I would expect that test contains the value of the last conversion, but it just contains a 1 which isn't correct.

The problem I have is if I use exactly (!!) the same code in a "normal" Code Warrior project without any MAC software, it works fine and the register of the MCU contains the values I expected.

Has anybody an idea what I have to do to use the ADC in combination with the 802.15.4 MAC SW?

Labels (1)
0 Kudos
4 Replies

397 Views
Ware
Contributor III
 
You need to wait for the CCF (conversion complete flag) to be set before reading the result.
 
Code:
  ATDPE=0b00000100;  ATDC=0b10100000;  ATDSC=0b00100010;  while( !(ATDSC & 0b10000000) );  // wait for CCF  test=ATDRH;

 

- Ware

 


 
0 Kudos

397 Views
PaoloPinkel
Contributor I
First of all thanks for your answer!

But that doesn't fix the error. In an endless loop I'm just writing the result register into test. I've chosen the continuous conversion and if the current conversion would not be complete I would read ATDRH a little bit later and then the result would be available. The CCF flag is set but the result is still a single "1"...

As I mentioned before, the code is working in an other project, so the problem is not the use of the ADC in general but just the use in combination with the MAC SW.

Actually I'm a little bit despaired... :smileysad:
0 Kudos

397 Views
Ware
Contributor III
 
PaoloPinkel,
 
I don't think it could be the 802.15.4 MAC, because there are demos with the accelerometer that use the ATD peripheral.  (You might want to try the accelerometer demo for a sanity check).
 
Even though you are doing continuous conversions you should wait for CCF, especially since you write to ATDPE register every time through the loop (which ABORTS/RESTARTS the conversion which would prevent you from getting a good result until CCF).
 
 - Ware


Message Edited by Ware on 2007-08-09 08:27 AM
0 Kudos

397 Views
PaoloPinkel
Contributor I
Sorry, obviously the code example is a bit mistakable. Of course the initialization takes places before the while loop, so it looks something like that:
Code:
Init_ADC();while (1) {  test=ATDRH;}....static void Init_ADC(void) {  ATDPE=0b00000100;  ATDC=0b10100000;  ATDSC=0b00100010;}

 So I'll take a look at the accelerometer example, perhaps it helps me finding the error...




0 Kudos