Ok I've looking into the examples and I've gotten to the point where I get a clock out through the UCLK pin (3.7MHz) which matches my desired 9600 bauds at a 372 oversampling rate.
However, despite seeing the target device sending data through I/O line at the desired baud rate utilising a protocol analyzer, I cannot pick up this data with the USART (the interrupt never triggers).
I attempted to send data as well but I can't manage to get anything out either. I am following the example that was linked. It doesn't look like you have to do anything too fancy to get it to work, but I don't seem to get anything out. If I disable the smartcard mode it starts transmitting straight away at 9600 bauds (leaving all the other config as is) but of course this is not what I want.
I am quite confused as to what would be causing this, but I haven't really found anyone who's talked about getting this particular part to work with this interface to really have a 1 to 1 comparison or anything to go on with.
Here is a bit of the code I am using:
/* Initialize debug output via UART for board */
void smartcardInit(void)
{
uint32_t temp = 0;
Chip_SCU_PinMuxSet(SC_TXD_PORT, SC_TXD_PIN, SC_TXD_FUNC_USART);
Chip_SCU_PinMuxSet(SC_UCLK_PORT, SC_UCLK_PIN, SC_UCLK_FUNC_USART);
/* Enable UART clocking. UART base clock(s) must already be enabled */
Chip_Clock_EnableOpts(SC_USART_CLK, true, true, 1);
/* Enable smartcard mode;
* After reset -> ISO 7816-3 compliant asynchronous smart card mode T=0 */
SC_USART->SCICTRL |= UART_SCICTRL_SCIEN;
/* USARTConfig */
NVIC_DisableIRQ(SC_USART_IRQ);
// Databits, stopbits & parity
Chip_UART_ConfigData(SC_USART, UART_LCR_WLEN8 | UART_LCR_SBS_2BIT | UART_LCR_PARITY_EN | UART_LCR_PARITY_EVEN);
/* Calculate clock divider for given baudrate. Round the number by (temp * 2 + 1) / 2 */
temp = ( Chip_Clock_GetRate(SC_USART_CLK) / (SC_OVERSAMPLE / 2) ) / SC_BAUDRATE_STD ; /* baud rate */
temp = (temp + 1) >> 1;
Chip_UART_EnableDivisorAccess(SC_USART);
SC_USART->DLM = (uint32_t) (temp >> & 0xff;
SC_USART->DLL = (uint32_t) temp & 0xff;
SC_USART->OSR = (SC_OVERSAMPLE - 1) << 4;
Chip_UART_DisableDivisorAccess(SC_USART);
/* Smartcard configuration */
SC_USART->SCICTRL &= ~((0xffUL << | (0x3UL << 5)); /* clear guard bits and retries */
SC_USART->SCICTRL |=
(UART_SCICTRL_GUARDTIME(1)) | /* guard bits */
(UART_SCICTRL_TXRETRY(0)); /* retries */
NVIC_EnableIRQ(SC_USART_IRQ);
/***************************************************************************/
Chip_UART_IntEnable(SC_USART, (UART_IER_RBRINT | UART_IER_THREINT | UART_IER_RLSINT));
Chip_UART_SetupFIFOS(SC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0) );
/* Enable UART Transmit */
Chip_UART_TXEnable(SC_USART);
}
void smartcardWrite(void){
// SC_USART->SCICTRL = 0; // if I disable the smart card mode it sends data but of course it doesn't fit what I want
uint8_t msg[16] = "abcdefghijklmnop";
Chip_UART_SendByte(SC_USART, msg[0]);
Chip_UART_SendByte(SC_USART, msg[1]);
Chip_UART_SendByte(SC_USART, msg[2]);
Chip_UART_SendByte(SC_USART, msg[3]);
// Chip_UART_SendBlocking(SC_USART, msg, 16);
}
I also tried doing:
/* THRE status, contain valid data */
if ( (SC_USART->LSR & (UART_LSR_THRE)) )
{
Chip_UART_SendByte(SC_USART, *msg);
}
But once you write something to the THR register LSR becomes 0 and never changes state again, indicating the data never gets through the FIFO onto the TSR to actually be sent.
I'd appreciate any help with this.
Best regards.