Pages: [1]   Go Down
Author Topic: USART1 SPI slave mode, does not transmit data on TX  (Read 475 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
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:
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
Logged

Pages: [1]   Go Up
Jump to: