Measuring temperature using digital sensor DS18B20 and Arduino Multifunction Shield on FRDM K64F

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Measuring temperature using digital sensor DS18B20 and Arduino Multifunction Shield on FRDM K64F

Measuring temperature using digital sensor DS18B20 and Arduino Multifunction Shield on FRDM K64F

Measuring temperature using digital sensor DS18B20 and Arduino Multifunction Shield on FRDM K64F

 This tutorial describes a simple application for measuring temperature using the digital sensor DS18B20 and the Arduino Multifunction Shield connected to FRDM K64F. You can use new feature Expansion Boards (expansion shields) included in the Pins tool v9. This feature enables quick integration of shields in an application without the need to study manuals.

In this paper, you can find the environment setup, 1-wire protocol basics, and the steps of preparing a code with MCUXpresso tools (Peripherals and Pins tool).

Setup environment

  1. Install MCUXpresso IDE v11.3.0 or later and SDK FRDM-K64F 2.8.2 or later.
  2. Use the FRDM K64F EVK board https://www.nxp.com/webapp/Download?colCode=FRDMK64FUG.
  3. Connect the Arduino Multifunction shield (Expansion Board) to the FRDM K64F EVK board and DS18B20 to the Arduino shield.
  4. Connect the EVK board to the PC via a USB cable.
antonintomanec_0-1630312696869.png

Figure 1 FRDM K64F EVK board with Arduino Multi-Function shield

  1. Have the expansion board definition file arduino_multifunction_ds18b20.xml. For detailed instructions on how to create the expansion board see the following article: Creating expansion board definition file for Arduino Multifunction shield

DS18B20 Programmable Resolution 1-Wire Digital Thermometer

See the documentation https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

This tutorial uses powering with an external supply.

antonintomanec_1-1630312696885.png

Figure 2 Powering the DS18B20 with an External Supply

 

See the timing diagrams for communication with the DS18B20, needed for writing 1-Wire communication protocol.

antonintomanec_2-1630312696915.png

Figure 3 Initialization Timing

antonintomanec_3-1630312696957.png

Figure 4 Read/Write Time Slot Timing Diagram

The application only uses the following 1-wire protocol commands:

  • ‘CCh’ skip ROM command - only one slave on the bus supported
  • ’44h’ convert temperature
  • ‘BEh’ read DS18B20 registers (temperature)

Create the application in MCUXpresso IDE

Begin with the hello_word example from SDK, rename the project to frdmk64_termometer.

Steps to configure timer in the Peripherals tool:

  1. Go to the Peripherals tool and add/configure the PIT component. Resolve the new Error in Problems view by adding the SDK component to the project.antonintomanec_4-1630312697154.png

    Figure 5 PIT component in the Peripherals tool

Steps to apply the expansion board and configure pin in Pins tool:

  1. Apply the expansion board (arduino_multifunction_ds18b20.xml) from menu Pins -> Apply Expansion Board menu

  antonintomanec_12-1630314986052.png

Figure 6 Apply expansion board dialog

  1. The Expansion Board Routing dialog is automatically opened after step 1. It provides the possibility to route signals to processor pins that are connected to the expansion board. By default, all pins are routed automatically, see below. Keep only pin A4 routed which is needed for our thermometer application. Unroute the unneeded pins by clicking the Route column or later in the Routing Details view, then click Apply.

 antonintomanec_13-1630315164863.png

Figure 7 Expansion board routing dialog 

  1. The action results in the following setting. When selecting Expansion board in the Labels combo, you see the labels as they are marked on the Arduino shield. antonintomanec_7-1630312697668.png

Figure 8 Expansion header view

  1. In the Routing Details view, set the electrical properties of the pin (Direction, Pull select, Pull enable).

    antonintomanec_15-1630315361190.png

Figure 9 Electrical properties in the Routing Details view

  1. Click Update Code to update the project with the code generated by the tools.

Write the thermometer application and 1-wire protocol (thermometer.c)  

Rename the source file hello_world.c to thermometer.c and follow the steps below. Find the completed thermometer.c in the project

  1. Use the PIT timer to create methods delayMS() and delayUS() for delays of μs and ms. See the PIT interrupt handler PIT_CHANNEL_0_IRQHANDLER() function.  
  2. Write methods GPIO_low() and GPIO_high() to set the ARDUINO_A4_PIN to logical 0 and 1. These methods are based on the code which is in the screenshot below.antonintomanec_9-1630312697858.png

    Figure 10 Generated code for ARDUINO_A4_PIN

  3. Write methods for reading/writing bytes to the 1-wire bus.antonintomanec_10-1630312697916.png

Figure 11 Methods for reading/writing bytes

  1. Write methods to request the temperature conversion and read the temperature, see dsRequestConvertTemp() and dsReadTemp(). Finally, use the methods in main().

 

Build the project and start debugging.

antonintomanec_11-1630312697943.png

Figure 12 Output from the application

添付
評価なし
バージョン履歴
最終更新日:
‎02-23-2022 12:51 AM
更新者: