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.
I have an EK-TM4C129XL that is to be control from Matlab on PC over serial/UART.
The problem is that the transmissions from PC do not trigger the receive interrupt. I do not forget to "resume" before trying.
Please check if I correctly configure everything. Here is the relevant code.
void initPCInterface(uint32_t sys_clk) { SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, 0b00000011); UARTConfigSetExpClk(UART0_BASE, sys_clk, 57600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTFIFOEnable(UART0_BASE); UARTFIFOLevelSet(UART0_BASE,UART_FIFO_TX2_8, UART_FIFO_RX2_8); UARTIntEnable(UART0_BASE, UART_INT_RX); UARTIntRegister(UART0_BASE, pcCommInterface); IntPrioritySet(INT_UART0,0x20);//MEDIUM PRIORITY IntEnable(INT_UART0); }
void initGPIO(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, PB_MASK); GPIOPinWrite(GPIO_PORTB_BASE, PB_MASK,0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOP)); GPIOPinTypeGPIOOutput(GPIO_PORTP_BASE, PP_MASK); GPIOPinWrite(GPIO_PORTP_BASE, PP_MASK,0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE)); GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, PE_MASK); GPIOPinWrite(GPIO_PORTE_BASE, PE_MASK,0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOC)); GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, PC_MASK); GPIOPinWrite(GPIO_PORTC_BASE, PC_MASK,0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOQ)); GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, PQ_MASK); GPIOPinWrite(GPIO_PORTQ_BASE, PQ_MASK,0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOK)); GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, PK_MASK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)); //Unlock PD7, default NMI HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80; GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, PD_MASK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOM)); GPIOPinTypeGPIOInput(GPIO_PORTM_BASE, PM_MASK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)); GPIOPinTypeGPIOInput(GPIO_PORTN_BASE, PN_MASK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)); GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, PA_MASK); }
int main(void) { {// limit scope of sys_clock uint32_t sys_clock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); initGPIO(); initPCInterface(sys_clock); }//sys_clock is popped from stack IntMasterEnable(); while(true); }
minimal Matlab test. Matlab successfully opens the port
clear close all s=serial('/dev/ttyS0',... 'BaudRate', 57600,'DataBits', 8,'Parity', 'none', ... 'StopBits',1, 'Timeout',2); fopen(s);%successful fprintf(s, 'rzzzzzklkll');%send something, does nothing fclose(s);
Hello Andrey,
Do you have the pcCommInterface interrupt properly registered in startup_ccs.c?
If you pause the debug, is it in the while loop or did it get caught in an ISR?
For readability, I recommend chaning
GPIOPinTypeUART(GPIO_PORTA_BASE, 0b00000011);
with
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
I switched from interrupt to polling and it turns out the µC receives nothing. I stopped in the debugger to look in the receive status register. It shows no error.
Now I am lost. I don't know where to look further. perhaps i try to send something with Putty and look if can be received from there
Putty produces no reaction either.
sudo setserial -bg /dev/tty* shows
/dev/ttyS0 at 0x03f8 (irq = 4) is a 16550A
and the rest
Cannot get serial info: Inappropriate ioctl for device
so ttyS0 is the only valid serial port.
It turns out I have some problem with Linux. I installed CCS on my Windows laptop and it works.
Hello Andrey,
Ah okay, thanks for letting us know. I'll go ahead and close this thread then. Good luck with Linux debugging.
To be more exact the port is /dev/ttyACM0, not ttyS0. It works with Putty, but not in Matlab, because Matlab only recognizes /dev/ttyS* ports, but that is of course different story...