Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Compiler/LAUNCHXL-F28379D: Reading SCIA via c program returning wrong/chaning number

$
0
0

Part Number: LAUNCHXL-F28379D

Tool/software: TI C/C++ Compiler

I've created a Simulink model in which I am sending a value from a CONSTANT source via SPI XMT block. Ive included a DATA CONVERSION block to uint16 (SI)  because I'm aware not all data types are supported and data must be in SI forma - correct me if I'm wrong.

To read the data, I've written C code as follows in the Visual Studio Code Program:

#include <windows.h>
#include <stdio.h>

int main()
{
        HANDLE hComm;

        hComm = CreateFile("COM8",//COM Port is correct.
                            GENERIC_READ,//we r just reading
                            0,//disabled sharing, 
                            NULL,//No Security Needed
                            OPEN_EXISTING,//open existing port
                            0,//Non-overlapped, since only one program will be using data
                            NULL);//is NULL for COM devices
                            
        if(hComm == INVALID_HANDLE_VALUE)//Error check
            printf("Error in opening serial port/invalid value");
        else
            printf("COM Port successfully opened");

        CloseHandle(hComm);//closes the USB port, so it is again accessible by other programs.

        return 0;

}
I've checked numerous times, and I'm 99.99% sure I have the correct COM port - device manager told me. However, once i execute the C program and place a breakpoint before CloseHandle(), the value is in hexadecimal format and wayyyy incorrect. On top of that, the value changes from debug session to debug session, without me changing the value in the Simulink Model constant source. The values I've measured are between 0x5C and 0x98 with some numbers showing up more prominently than others.
Is there something I am not converting that I should be? Is it a transmitting problem?
I'm sure the answer is easily solved, I am new to UART programming. Looking forward to any help to be offered!

Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>