MSP432 UART printf to PC

 


マルチビットを読み込むのは、以前できていたので、今度は文字列をPCの送付する。

こちらはコードを書くというより、printfを使えるようにする。

https://43oh.com/2015/05/how-to-add-printf-support-for-the-msp432-launchpad-serial-port/

の通り。

手順

【前準備】

https://github.com/bluehash/MSP432Launchpad

に行って、[↓CODE]のボタンをクリックしてDownLoad zipを選択してファイルをダウンロード。ZIPを解凍する。


必要なのは

printfOverride.c

というファイルで、これをCCSのプロジェクトにドラッグ、コピーするか、移動してくるか?聞かれるがコピー。

printfOverride.cを開いて、13行目にdriverlib.hをインクルードしているが、パスが通っていないので、#include <ti/devices/msp432p4xx/driverlib/driverlib.h>に置き換えをする。



準備はこれで終わり。

【使い方】

普通のc言語でprintfを使うので

#include <stdio.h>

をインクルードしておく。UARTなどの設定は、これまで通り。

ダウンロードしたフォルダーに例があるように普通にprintfが使える。

printf("\r\nPrintf support for the launchpad\r\n");

printf("Decimal(10) :%d\r\n", 10);

printf("Hex(10)     :%x\r\n", 10);

printf("float       :%f\r\n", 4.32);


以下は例。スイッチを押すとコンソールに、0から9までカウントアップしていき表示する例。

/* --COPYRIGHT--,BSD

 * Copyright (c) 2017, Texas Instruments Incorporated

 * All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 *

 * *  Redistributions of source code must retain the above copyright

 *    notice, this list of conditions and the following disclaimer.

 *

 * *  Redistributions in binary form must reproduce the above copyright

 *    notice, this list of conditions and the following disclaimer in the

 *    documentation and/or other materials provided with the distribution.

 *

 * *  Neither the name of Texas Instruments Incorporated nor the names of

 *    its contributors may be used to endorse or promote products derived

 *    from this software without specific prior written permission.

 *

 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,

 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR

 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR

 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,

 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,

 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;

 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR

 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,

 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 * --/COPYRIGHT--*/

/******************************************************************************

 * MSP432 Empty Project

 *

 * Description: An empty project that uses DriverLib

 *

 *                MSP432P401

 *             ------------------

 *         /|\|                  |

 *          | |                  |

 *          --|RST               |

 *            |              P1.1|Switch

 *            |                  |

 *            |                  |

 *            |                  |

 *            |                  |

 * Author: 

*******************************************************************************/

/* DriverLib Includes */

#include <ti/devices/msp432p4xx/driverlib/driverlib.h>


/* Standard Includes */

#include <stdint.h>

#include <stdbool.h>

#include <stdio.h>//printf


/* UART Configuration Parameter. These are the configuration parameters to

 * make the eUSCI A UART module to operate with a 9600 baud rate. These

 * values were calculated using the online calculator that TI provides

 * at:

 *http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html

 */

const eUSCI_UART_ConfigV1 uartConfig =

{

        EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source

        78,                                     // BRDIV = 78

        2,                                       // UCxBRF = 2

        0,                                       // UCxBRS = 0

        EUSCI_A_UART_NO_PARITY,                  // No Parity

        EUSCI_A_UART_LSB_FIRST,                  // LSB First

        EUSCI_A_UART_ONE_STOP_BIT,               // One stop bit

        EUSCI_A_UART_MODE,                       // UART mode

        EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION,  // Oversampling

        EUSCI_A_UART_8_BIT_LEN                  // 8 bit data length

};


int main(void)

{


    /* Stop Watchdog  */

    MAP_WDT_A_holdTimer();


    /* PIN setting*/

    MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);


    /* Setting DCO to 12MHz */

    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);



    /* Selecting P1.2 and P1.3 in UART mode */

     MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,

             GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);



    /* Configuring UART Module */

       MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);


       /* Enable UART module */

       MAP_UART_enableModule(EUSCI_A0_BASE);


       /* Enabling interrupts */

       MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);

       MAP_Interrupt_enableInterrupt(INT_EUSCIA0);

      // MAP_Interrupt_enableSleepOnIsrExit();

       MAP_Interrupt_enableMaster();



       uint8_t num=0;

    while(1)

    {

        if(MAP_GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN1)==GPIO_INPUT_PIN_LOW){


        for (num = 0; num < 10; num++){

            printf("Printf test\r\n");

            printf("number      :%d\r\n", num);

            printf("float       :%6.4f\r\n", 3.141592);

               }

               num = 0;

        }

    }

}

コメント

このブログの人気の投稿

Attiny85とAQM0802A(LCD)のI2C接続

ILI9341 240X320 Arduino

Attiny85 FuseRest