Hi Mac,
Thanks for your post. Regarding the baud rate, I was using 9600 for the standalone DS1822 code. This was using a bus frequency of 4 Mhz initially but I was able to modify it to use an 8 Mhz bus frequency. To do this, I just modified the code as you suggested to add successive delays of the maximum amount until I reached the required delay amount (eg. 480 us). My BR values for 9600 with 4 Mhz was 0x1A and with 8 Mhz and 9600 it was 0x34. The SCI module worked perfectly for both the 8 Mhz and 4 Mhz standalone DS1822 code. Now that I have this 'standalone' application working I want to try to include this code in the generic Zigbee application (smac-per-tx) provided with the Beekit software. There are various other sample Zigbee applications that may work better for me to integrate this DS1822 into but I haven't found any code simpler than the smac-per-tx application as of yet. In your previous posts, I think you may have anticipated the issues I am having now. I tried to simply add the header files you created for the DS1822 into the smac-per-tx(Zigbee) project. Then in the main I simply tried to call the temperature conversion function and copy the result into a variable that I could transmit using the Zigbee code already in place.
You mentioned:
Another alternative is to start a conversion within the function. Then, using a periodic timer interrupt, say every 10ms, to test for completion of the conversion, and then read the scratchpad when the conversion has finished. This process is more complex, but does allow other processing to occur, including Zigbee operations, during the conversion period.
Perhaps this is related to my problem because I have not tried creating a periodic timer interrupt that will poll for conversion and then read the scratchpad. It seems as though either the timing for talking to the DS1822 is off when I try to use the working code in the Zigbee application or a second alternative may be that I am not calling the temperature conversion function at the appropriate time. Would you be able to give me an idea of how I would create a simple periodic timer interrupt every 10 ms to test for completion of the temperature conversion and then read the scratchpad afterwards. This may be the root of my problem when I try to use the DS1822 code in the Zigbee application.
You will also need to ascertain whether the global disabling of interrupts for the periods necessary for one-wire operation, will give problems for Zigbee operation.
I have tested this out and it seems that globally disabling interrupts does not affect Zigbee operation. I am using the same header files that you posted and just calling the DS1822 functions you posted which disable and then enable interrupts again and the Zigbee operations seem to continue undisturbed. I have confirmed that I am able to send and receive simple Zigbee packets while I am making use of the temperature conversion function.
Yet another possibility is to utilize the CLK0 output from the wireless modem as an external reference for the MCU (FEE or FBE mode). But the modem would need to be active during the temperature measurement process, and during SCI communications, (if applicable).
It seems that the Zigbee application may be using this approach but I am not 100% certain. I have posted the code to see if perhaps you could take a quick look and see where I may have gone wrong in my approach. After I added the previously mentioned DS1822 header files to the project and called the temperature conversion function in main, the code compiles just fine but I do not receive the temperature information on the receiving board. However, if I replace the temperature function with just regular integer values I can receive these values just fine on the receiving board via Hyper Terminal.
I should also mention a few more things about the code I posted below. In the temperature conversion function I found that for the DS1822's I needed to start reading from byte 0 and 1 first and this would give me the correct temperature information. This is why I changed this part of the temperature converstion function but everything else works perfectly. I tried calling the temperature conversion function from multiple places within the zigbee application but nothing seems to work maybe for the reasons mentioned already. The two places where the zigbee application sends information, from what I understand, are shown below. They can also be seen in the code in attached. Thanks for your help. I greatly appreciate it.
switch (app_status) { case INITIAL_STATE: //Walk the LEDs //For TX LED1 = LED_OFF; //Turn off all LEDs LED2 = LED_OFF; LED3 = LED_OFF; LED4 = LED_OFF; LED1 = LED_ON; //Lights LED1 for (loop = 0; loop < LED_DELAY; loop++); LED1 = LED_OFF; LED2 = LED_ON; //Lights LED2, Turns off LED1 for (loop = 0; loop < LED_DELAY; loop++); LED2 = LED_OFF; LED3 = LED_ON; //Lights LED3, Turns off LED2 for (loop = 0; loop < LED_DELAY; loop++); LED3 = LED_OFF; LED4 = LED_ON; //Lights LED4, Turns off LED3 for (loop = 0; loop < LED_DELAY; loop++); LED4 = LED_OFF; //Turns off LED4 LED1 = LED_ON; app_status = IDLE_STATE; //Switch app status to TX_STATE temp=Temperature(); tx_data_buffer[0] = 0; tx_data_buffer[1] = temp; tx_data_buffer[2] = temp; tx_data_buffer[3] = temp; tx_data_buffer[4] = temp; tx_data_buffer[5] = temp; tx_data_buffer[6] = temp; tx_data_buffer[7] = temp; tx_data_buffer[8] = temp; tx_data_buffer[9] = temp; tx_packet.u8DataLength = 10; //Set the data length of the packet. in this case, 6. packet_count=0; break;
/* See if START TX has been hit */ if ((gu16Events & KBI2_EVENT) != 0) { #if BUZZER_ENABLED BUZZER = BUZZER_ON; #endif delay(10); #if BUZZER_ENABLED BUZZER = BUZZER_OFF; #endif gu16Events &= ~KBI2_EVENT; /* Clear the event */ packet_count=0; setLedsMode(LED_DIGIT_MODE, (UINT16) 8421, 10, LED_NO_FLAGS); temp=Temperature(); tx_data_buffer[0] = 0; tx_data_buffer[1] = temp; tx_data_buffer[2] = temp; tx_data_buffer[3] = temp; tx_data_buffer[4] = temp; tx_data_buffer[5] = temp; tx_data_buffer[6] = temp; tx_data_buffer[7] = temp; tx_data_buffer[8] = temp; tx_data_buffer[9] = temp; //Set the data length of the packet. in this case, 6. tx_packet.u8DataLength = 10; packet_count=0; app_status = TX_STATE; }