Part Number: MSPM0G3507
#include "ti_msp_dl_config.h"
volatile bool gCheckRXMessage;
volatile uint8_t gMsgCount;
volatile bool gError;
volatile bool gTransmitComplete;
#define DL_MCAN_MSG_INT (0x81200)
#define DAC12_REF_VOLTAGE_mV (3300)
uint16_t gcOutputSignalGroup[]={4095,4095};
//Configure the signal to output on DAC
#define OUTPUT_SIGNAL gcOutputSignalGroup
#define OUTPUT_SIGNAL_SIZE (sizeof(OUTPUT_SIGNAL) / sizeof(uint16_t))
volatile uint32_t gCounter;
//void processData(uint8_t *data);
int main(void)
{
DL_MCAN_TxBufElement txMsg;
DL_MCAN_RxBufElement rxMsg;
DL_MCAN_RxNewDataStatus newData;
SYSCFG_DL_init();
NVIC_EnableIRQ(DAC12_INT_IRQN);
//gCounter = 0;
/* Initialize message to transmit. */
/* Identifier Value. */
txMsg.id = ((uint32_t)(0x4)) << 18U;
/* Transmit data frame. */
txMsg.rtr = 0U;
/* 11-bit standard identifier. */
txMsg.xtd = 0U;
/* ESI bit in CAN FD format depends only on gError passive flag. */
txMsg.esi = 0U;
/* Transmitting 4 bytes. */
txMsg.dlc = 4U;
/* CAN FD frames transmitted with bit rate switching. */
txMsg.brs = 1U;
/* Frame transmitted in CAN FD format. */
txMsg.fdf = 1U;
/* Store Tx events. */
txMsg.efc = 1U;
/* Message Marker. */
txMsg.mm = 0xAAU;
/* Data bytes. */
txMsg.data[0] = 0x12;
txMsg.data[1] = 0x34;
txMsg.data[2] = 0x56;
txMsg.data[3] = 0x78;
NVIC_EnableIRQ(MCAN0_INST_INT_IRQN);
gMsgCount = 0;
gError = false;
while (1) {
/* Write Tx Message to the Message RAM. */
DL_MCAN_writeMsgRam(MCAN0_INST, DL_MCAN_MEM_TYPE_BUF, 1U, &txMsg);
/* Enable Transmission interrupt.*/
DL_MCAN_TXBufTransIntrEnable(MCAN0_INST, 1U, 1U);
/* Add request for transmission. */
DL_MCAN_TXBufAddReq(MCAN0_INST, 1U);
/*
* Wait for flag interrupt to be triggered and flag to check received
* message is set to true.
*/
gCheckRXMessage = false;
while (false == gCheckRXMessage) {
__WFE();
}
/*
* Extract received message from MCAN RAM RX buffer and copy content to
* rxMsg
*/
DL_MCAN_readMsgRam(MCAN0_INST, DL_MCAN_MEM_TYPE_BUF, 0U,
DL_MCAN_RX_FIFO_NUM_1, &rxMsg);
DL_MCAN_getNewDataStatus(MCAN0_INST, &newData);
DL_MCAN_clearNewDataStatus(MCAN0_INST, &newData);
/*
* Check that received data matches sent data.
* Device will halt here during debug if data doesn't match.
*/
if ((txMsg.data[0] != rxMsg.data[0]) ||
(txMsg.data[1] != rxMsg.data[1]) ||
(txMsg.data[2] != rxMsg.data[2]) ||
(txMsg.data[3] != rxMsg.data[3])) {
/* Trap code execution */
gError = true;
while (1) {
__BKPT(0);
}
} else {
/* Increment message count if message is received. */
gMsgCount++;
gcOutputSignalGroup[0] = rxMsg.data[0] << 8;
gcOutputSignalGroup[0] += rxMsg.data[1];
gcOutputSignalGroup[1] = rxMsg.data[2] << 8;
gcOutputSignalGroup[1] += rxMsg.data[3];
}
}
}
void MCAN0_INST_IRQHandler(void)
{
uint32_t intrStatus;
switch (DL_MCAN_getPendingInterrupt(MCAN0_INST)) {
case DL_MCAN_IIDX_LINE1:
/* Check MCAN interrupts fired during TX/RX of CAN package */
intrStatus =
DL_MCAN_getIntrStatus(MCAN0_INST) & MCAN0_INST_MCAN_INTERRUPTS;
DL_MCAN_clearIntrStatus(
MCAN0_INST, intrStatus, DL_MCAN_INTR_SRC_MCAN_LINE_1);
/*
* Check if MCAN interrupts set correspond to a complete
* transmission and reception of a CAN package.
*/
if (DL_MCAN_MSG_INT != intrStatus) {
if (gMsgCount == MCAN0_INST_MCAN_FIFO_1_NUM) {
gTransmitComplete = true;
} else {
gError = true;
}
/*
* Check gTransmitComplete to see if transmit is complete,
* or gError if there was an error
*/
__BKPT(0);
} else {
gCheckRXMessage = true;
}
break;
default:
gError = true;
break;
}
}
void DAC12_IRQHandler(void)
{
switch (DL_DAC12_getPendingInterrupt(DAC0)) {
case DL_DAC12_IIDX_FIFO_1_2_EMPTY:
//if(gMsgCount > 0){
DL_DAC12_output12(DAC0, OUTPUT_SIGNAL[0]);
/*DL_GPIO_writePins(GPIOA_PORT, GPIOA_led_PIN);
delay_cycles(100000000);
DL_GPIO_clearPins(GPIOA_PORT, GPIOA_led_PIN);*/
//}
/*if (gCounter >= OUTPUT_SIGNAL_SIZE) {
gCounter = 0;
}*/
break;
default:
break;
}
}
I added a section of the DAC output to can's loopback sample code, but he is no longer working.
I want to use an oscilloscope to observe the waveform that DATA transmits to the DAC output.