Go Down

Topic: USART1 SPI slave mode, does not transmit data on TX (Read 581 times) previous topic - next topic

darighi

Hello guys,
I need help to set the USART1 as SPI slave MODE3 and send a few bytes when I receive a byte on RX pin.
All must happen into the interrupt RX.
The RX interrupt works fine because into my RX handler I increment a variable every time it enter and when I print it on my display  I see that it increments, but when I send a byte, nothing comes out, and the TX pin PA13 is always low.
I tryed to switch the PIN PA13 as normal I/O, to see if the pin works fine, and it works fine.
I post my code:

my defines
Code: [Select]

#define USART_SPI_PORT_ENABLE REG_PIOA_PER //Pio Enable
#define USART_SPI_PORT_OER REG_PIOA_OER //Pio Output enable
#define USART_SPI_PORT_ODR REG_PIOA_ODR    //PIo Input enable
#define USART_SPI_PORT_OWER REG_PIOA_OWER //Pio Output Mask
#define USART_SPI_PORT_OWDR REG_PIOA_OWDR //Pio Unmask output
#define USART_SPI_PORT_PUER REG_PIOA_PUER //Pio Pull up setup
#define USART_SPI_PORT_PUDR REG_PIOA_PUDR //Pio remove Pull UP
#define USART_SPI_PORT_MDDR REG_PIOC_MDDR   //Pio disable open drain
#define USART_SPI_PORT_ODSR REG_PIOA_ODSR //Pio Register I/O
#define USART_SPI_PORT_PDSR REG_PIOA_PDSR   //Pio Status Register, used to read input

#define USART1_MOSI PIO_PA12 //input
#define USART1_MISO PIO_PA13 //output
#define USART1_SCK PIO_PA16 //input
#define USART1_SS PIO_PA15 //input

#define USART_SPI_SLAVE_COM USART1
#define USART_SPI_SLAVE_COM_IRQn USART1_IRQn
#define USART_SPI_SLAVE_COM_Handler USART1_Handler
#define USART_SPI_SLAVE_COM_IRQ_PRIORITY         7


My USART initializzation
Code: [Select]

const usart_spi_opt_t usart_spi_settings = {
.spi_mode =  SPI_MODE_3,
.char_length = US_MR_CHRL_8_BIT,
.channel_mode = US_MR_USART_MODE_SPI_SLAVE 
};

void usart_spimode_init( void )
{
/* Set USART1 piins */
USART_SPI_PORT_ENABLE = ( USART1_MISO | USART1_MOSI | USART1_SCK | USART1_SS );
USART_SPI_PORT_OER = USART1_MISO ;
USART_SPI_PORT_ODR = (USART1_MOSI | USART1_SCK | USART1_SS);
USART_SPI_PORT_OWER = USART1_MISO ;
USART_SPI_PORT_OWDR = (USART1_MOSI | USART1_SCK | USART1_SS);
        USART_SPI_PORT_PUER = (USART1_MOSI | USART1_SCK | USART1_SS);

/*Enable clock to USART1*/
sysclk_enable_peripheral_clock(BOARD_ID_USART1);
sysclk_enable_peripheral_clock(PIOA);

/* Configure USART AS SPI SLAVE MODE 3, 8 BIT . */
usart_init_spi_slave(USART_SPI_SLAVE_COM, &usart_spi_settings);

/* enable rx and tx */
usart_enable_tx(USART_SPI_SLAVE_COM);
usart_enable_rx(USART_SPI_SLAVE_COM);

       /*enable usart1 interrupt*/
NVIC_DisableIRQ(USART_SPI_SLAVE_COM_IRQn);
NVIC_ClearPendingIRQ(USART_SPI_SLAVE_COM_IRQn);
NVIC_SetPriority(USART_SPI_SLAVE_COM_IRQn, USART_SPI_SLAVE_COM_IRQ_PRIORITY); 
NVIC_EnableIRQ(USART_SPI_SLAVE_COM_IRQn);

/* USART Enable interrupt received BYTE */
usart_enable_interrupt(USART_SPI_SLAVE_COM, US_IER_RXRDY);
}


my My USART Handler
Code: [Select]

void USART1_Handler(void)
{
NVIC_DisableIRQ(USART_SPI_SLAVE_COM_IRQn);    // Diisable usart1 interrupt

count_debug += 1;

/*USED FOR DEBUG*/
REG_USART1_THR = 10;  //send a number

NVIC_ClearPendingIRQ(USART_SPI_SLAVE_COM_IRQn);
NVIC_EnableIRQ(USART_SPI_SLAVE_COM_IRQn);
}


Thanks for your help
Davide

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy