This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
Hi team,
my customer using TM4C1290 in some IND EE project, now customer kick off the A&T testing tool for testing the TM4C1290.
After checking the SDK of M4, Is there any example of serial port receive interrupt for TM4C1490? The two examples in the SDK both call blocking receive functions.
Tks for your checking here.
Hi,
Please refer to the example in C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\uart_echo. In this example, the receive side uses interrupt mode to echo back the data to the transmitter.
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = MAP_UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // MAP_UARTIntClear(UART0_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // while(MAP_UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART and write it back to the UART. // MAP_UARTCharPutNonBlocking(UART0_BASE, MAP_UARTCharGetNonBlocking(UART0_BASE)); // // Blink the LED to show a character transfer is occuring. // MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); // // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // SysCtlDelay(g_ui32SysClock / (1000 * 3)); // // Turn off the LED // MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); } }
Hi Tsal,
Now my customer also using TM4C1290 for two CAN communication for internal self test. using CAN0 and CAN1 ,but report the below error.
would you help to check the below code to help us fix this bug?
#include "test_can.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "stdio.h" #define CAN0_TX_LEN 4 #define CAN0_RX_LEN 4 #define CAN1_TX_LEN 4 #define CAN1_RX_LEN 4 tCANMsgObject Can1_TxMessage; tCANMsgObject Can1_RxMessage; uint8_t Can1_Tx_Buf[CAN1_TX_LEN]; uint8_t Can1_Rx_Buf[CAN1_RX_LEN]; uint8_t can1_flag = 0; tCANMsgObject Can0_TxMessage; tCANMsgObject Can0_RxMessage; uint8_t Can0_Tx_Buf[CAN0_TX_LEN]; uint8_t Can0_Rx_Buf[CAN0_RX_LEN]; uint8_t can0_flag = 0; void CAN0IntHandler(void) { int32_t ulStatus; // ͨ��CANIntStatus������ȡ�жϵ�״̬ ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE); // ����ǿ�����״̬�жϣ���˵��������ij�ִ��� if(ulStatus == CAN_INT_INTID_STATUS) { //��ȡCANģ��������״̬�����Զ�����жϡ� ulStatus = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL); printf("can0 error:%08X\r\n", ulStatus); } // ����Ƿ�����message object 1����ķ����ж� else if(ulStatus == 1) { // ���ݰ������Ѿ���ɣ�����ж� CANIntClear(CAN0_BASE, 1); printf("can0 send succees\r\n"); } // ����Ƿ�������message object 2����Ľ����ж� else if(ulStatus == 2) { // ���ݰ������Ѿ���ɣ�����ж� CANIntClear(CAN0_BASE, 2); printf("can0 receive succees\r\n"); can0_flag = 1;//˵�����յ����� } } void CAN1IntHandler(void) { int32_t ulStatus; // ͨ��CANIntStatus������ȡ�жϵ�״̬ ulStatus = CANIntStatus(CAN1_BASE, CAN_INT_STS_CAUSE); // ����ǿ�����״̬�жϣ���˵��������ij�ִ��� if(ulStatus == CAN_INT_INTID_STATUS) { //��ȡCANģ��������״̬�����Զ�����жϡ� ulStatus = CANStatusGet(CAN1_BASE, CAN_STS_CONTROL); printf("can1 error:%08X\r\n", ulStatus); } // ����Ƿ�����message object 1����ķ����ж� else if(ulStatus == 1) { // ���ݰ������Ѿ���ɣ�����ж� CANIntClear(CAN1_BASE, 1); printf("can1 send succees\r\n"); } // ����Ƿ�������message object 2����Ľ����ж� else if(ulStatus == 2) { // ���ݰ������Ѿ���ɣ�����ж� CANIntClear(CAN1_BASE, 2); printf("can1 receive succees\r\n"); can1_flag = 1;//˵�����յ����� } } void Can0_Init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinConfigure(GPIO_PA0_CAN0RX); ROM_GPIOPinConfigure(GPIO_PA1_CAN0TX); GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); ROM_CANInit(CAN0_BASE);// CAN�������ij�ʼ�� ROM_CANBitRateSet(CAN0_BASE, 120000000, 1000000); ROM_CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); ROM_CANRetrySet(CAN0_BASE, 0); ROM_IntEnable(INT_CAN0); IntRegister(INT_CAN0, CAN0IntHandler); ROM_CANEnable(CAN0_BASE); // CAN message ID:ʹ��10��Ϊ���ĵ�ID Can0_TxMessage.ui32MsgID = 10; // û��MASK���� Can0_TxMessage.ui32MsgIDMask = 0; //ʹ�ܷ����ж� Can0_TxMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE; //�������ݰ���СΪ4���ֽ� Can0_TxMessage.ui32MsgLen = sizeof(Can0_Tx_Buf); // ָ�������ݵ�ָ�� Can0_TxMessage.pui8MsgData = Can0_Tx_Buf; // ��ʼ���������ڽ��յı��Ķ��� // ���Խ����κ�ID�ı��Ķ��� Can0_RxMessage.ui32MsgID = 0; // û������ Can0_RxMessage.ui32MsgIDMask = 0; // ʹ�ܽ����жϺ�ID���� Can0_RxMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE|MSG_OBJ_USE_ID_FILTER; // �������8���ֽڵ����� Can0_RxMessage.ui32MsgLen = sizeof(Can0_Rx_Buf);; //��message object 2����Ϊ���ձ��Ķ��� CANMessageSet(CAN0_BASE, 2, &Can0_RxMessage, MSG_OBJ_TYPE_RX);//���� } void Can1_Init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIOPinConfigure(GPIO_PB0_CAN1RX); ROM_GPIOPinConfigure(GPIO_PB1_CAN1TX); GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN1); ROM_CANInit(CAN1_BASE);// CAN�������ij�ʼ�� ROM_CANBitRateSet(CAN1_BASE, 120000000, 1000000); ROM_CANIntEnable(CAN1_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); ROM_CANRetrySet(CAN1_BASE, 0); ROM_IntEnable(INT_CAN1); IntRegister(INT_CAN1, CAN1IntHandler); ROM_CANEnable(CAN1_BASE); // CAN message ID:ʹ��11��Ϊ���ĵ�ID Can1_TxMessage.ui32MsgID = 11; // û��MASK���� Can1_TxMessage.ui32MsgIDMask = 0; //ʹ�ܷ����ж� Can1_TxMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE; //�������ݰ���СΪ4���ֽ� Can1_TxMessage.ui32MsgLen = sizeof(Can1_Tx_Buf); // ָ�������ݵ�ָ�� Can1_TxMessage.pui8MsgData = Can1_Tx_Buf; // ��ʼ���������ڽ��յı��Ķ��� // ���Խ����κ�ID�ı��Ķ��� Can1_RxMessage.ui32MsgID = 0; // û������ Can1_RxMessage.ui32MsgIDMask = 0; // ʹ�ܽ����жϺ�ID���� Can1_RxMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE|MSG_OBJ_USE_ID_FILTER; // �������8���ֽڵ����� Can1_RxMessage.ui32MsgLen = sizeof(Can1_Rx_Buf);; //��message object 2����Ϊ���ձ��Ķ��� CANMessageSet(CAN1_BASE, 2, &Can1_RxMessage, MSG_OBJ_TYPE_RX);//���� } void Can0_Message_Get(void) { // ����ָ�������ݵĻ����� Can0_RxMessage.pui8MsgData = Can0_Rx_Buf; // ��ȡ���յ��ı��Ķ��� // ��message object�е���Ϣ��ȡ��Can0_RxMessage���ն����� CANMessageGet(CAN0_BASE, 2, &Can0_RxMessage, 0); if(Can0_RxMessage.ui32Flags & MSG_OBJ_DATA_LOST) { printf("CAN 0 message loss detected\r\n"); } printf("CAN 0 ReceiveMsgID = 0x%08X\nlen=%u\ndata:0x", Can0_RxMessage.ui32MsgID, Can0_RxMessage.ui32MsgLen); for(uint8_t uIdx=0;uIdx<Can0_RxMessage.ui32MsgLen;uIdx++) { printf("%02X ", Can0_RxMessage.pui8MsgData[uIdx]); } printf("\r\n"); } void Can0_Message_Send(uint8_t *data) { printf("CAN0 Send:0x"); for (uint8_t i=0;i<CAN0_TX_LEN;i++) { Can0_Tx_Buf[i] = data[i]; printf("%02X ", Can0_Tx_Buf[i]); } printf("\r\n"); CANMessageSet(CAN0_BASE, 1, &Can0_TxMessage, MSG_OBJ_TYPE_TX);//���� } void Can1_Message_Get(void) { // ����ָ�������ݵĻ����� Can1_RxMessage.pui8MsgData = Can1_Rx_Buf; // ��ȡ���յ��ı��Ķ��� // ��message object�е���Ϣ��ȡ��Can1_RxMessage���ն����� CANMessageGet(CAN1_BASE, 2, &Can1_RxMessage, 0); if(Can1_RxMessage.ui32Flags & MSG_OBJ_DATA_LOST) { printf("CAN 1 message loss detected\r\n"); } printf("CAN 1 ReceiveMsgID = 0x%08X\nlen=%u\ndata:0x",Can1_RxMessage.ui32MsgID,Can1_RxMessage.ui32MsgLen); for(uint8_t uIdx=0;uIdx<Can1_RxMessage.ui32MsgLen;uIdx++) { printf("%02X ",Can1_RxMessage.pui8MsgData[uIdx]); } printf("\r\n"); } void Can1_Message_Send(uint8_t *data) { printf("CAN1 Send:0x"); for (uint8_t i=0;i<CAN1_TX_LEN;i++) { Can1_Tx_Buf[i] = data[i]; printf("%02X ", Can1_Tx_Buf[i]); } printf("\r\n"); CANMessageSet(CAN1_BASE, 1, &Can1_TxMessage, MSG_OBJ_TYPE_TX);//���� } #if 0 int main(void) { ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_20MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_240), 120000000); IntMasterEnable(); //�����ж� Uart5_Init(); Uart6_Init(); Uart7_Init(); Timer0_Init(); Can0_Init(); Can1_Init(); printf("system init over\r\n"); printf("sysClock:%d\r\n", ui32SysClock); while(1) { uart_handler(); if (can0_flag) { Can0_Message_Get(); can0_flag = 0; } if (can1_flag) { Can1_Message_Get(); can1_flag = 0; } if (timer_100ms) { timer_100ms = 0; } if (timer_1s) { Can0_Message_Send((uint8_t*)"1234"); timer_1s = 0; } delay_ms(10); } } #endif
Hi,
There are CAN examples in C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\can. I will suggest the customer starts with simple_tx.c for one CAN controller and simple_rx.c for another controller on the network. To test these examples, a CAN network must be built meaning that a CAN transceiver is implemented for each CAN controller with proper termination resistor on the network.