cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 Discovery SPI Registers

cns1307
Associate II
Posted on August 21, 2014 at 16:14

I am trying to use theSTM32F429 Discovery boardin order to communicate in a transmit only mode to an LCD over SPI. However, every time I write to the data register to output, I see nothing get loaded in my debugging view (CrossStudio). I'm using Pin 4 for my CSS.

#include 
''stm32f4xx.h''
//#include 
''tm_stm32f4_spi.h''
#def
ine MODE_CLEAR (
1
<< 
5
) 
/* M0:M2 = 0b001 = 1 */
#def
ine MODE_UPDATE (
4
<< 
5
) 
/* M0:M2 = 0b100 = 4 */
#def
ine MODE_DISPLAY (
0
<< 
5
) 
/* M0:M2 = 0b000 = 0 */
unsigned char transmitData[
20
];
int main(void) {
int dummy;
int j;
SET_BIT(RCC->AHB
1
ENR,(RCC_AHB
1
ENR_GPIOCEN | RCC_AHB
1
ENR_GPIOAEN) );
MODIFY_REG(GPIOC->MODER,
(GPIO_MODER_MODER
10
| GPIO_MODER_MODER
12
) , 
(GPIO_MODER_MODER
10
_
1
| GPIO_MODER_MODER
12
_
1
) ); // Sets to alternate function
SET_BIT(GPIOC->OTYPER, (GPIO_OTYPER_OT_
10
| GPIO_OTYPER_OT_
12
)); // Set output to push-pull type
CLEAR_BIT(GPIOC->PUPDR, (GPIO_PUPDR_PUPDR
10
| GPIO_PUPDR_PUPDR
12
) ); // Disable push pull resistors
SET_BIT(GPIOC->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR
10
| GPIO_OSPEEDER_OSPEEDR
12
) ); // Set speed 
high
/* Set the Alternate Function for the SPI3 pins */
// Port C Pins 
7
-0
GPIOC->AFR[
0
] = 
0
x
00000000
; // PTC 
lower
order pins are 
default
// Port C Pins 
15
-8
GPIOC->AFR[
1
] = 
0
x
00066600
; // PTC pins 
10
, 
11
, and 
12
are for SPI (AF
6
= 
0
x
6
)
// Set up SS for 
screen
MODIFY_REG(GPIOA->MODER, GPIO_MODER_MODER
4
, GPIO_MODER_MODER
4
_
0
);
SET_BIT(GPIOA->BSRRL, 
0
b
10000
); //Sets pin 
4
high
// Enable the peripheral clock for SPI
3
SET_BIT(RCC->APB
1
ENR, RCC_APB
1
ENR_SPI
3
EN);
CLEAR_BIT(SPI
3
->CR
1
, SPI_CR
1
_CPHA); 
SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_CPOL);
//SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_BIDIMODE);
//SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_BIDIOE); 
SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_SSM);// Needed to enable single master
SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_SSI);// Needed to enable single master
SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_MSTR); // Set Master configuration
/* TODO: Set Baud to 2 MHz (not just a random prescaler) */
MODIFY_REG(SPI
3
->CR
1
, SPI_CR
1
_BR, SPI_CR
1
_BR); //Set to fCLK/
256
CLEAR_BIT(SPI
3
->CR
1
, SPI_CR
1
_LSBFIRST); // write out MSB first
SET_BIT(SPI
3
->CR
1
, SPI_CR
1
_SPE); // Enable SPI
3
transmitData[
0
]= MODE_CLEAR;
transmitData[
1
]=
0
x
00
;
for(j = 
0
; j < 
2
; j++) {
//TM_SPI_Send(SPI
3
, transmitData[j]);
SPI
3
->DR = transmitData[j]; // Write data to the data register
while( !(READ_BIT(SPI
3
->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
while( READ_BIT(SPI
3
->SR, SPI_SR_BSY) );
dummy = SPI
3
->DR;
}
SET_BIT(GPIOA->BSRRH, 
0
b
10000
); //Sets pin 
4
low

while(
1
){ 
transmitData[
0
]= MODE_UPDATE;
transmitData[
1
]=
0
x
00
;
SET_BIT(GPIOA->BSRRL, 
0
b
10000
); //Sets pin 
4
high
for(j = 
0
; j < 
2
; j++) {
//TM_SPI_Send(SPI
3
, transmitData[j]);
SPI
3
->DR = transmitData[j]; // Write data to the data register
while( !(READ_BIT(SPI
3
->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
while( READ_BIT(SPI
3
->SR, SPI_SR_BSY) );
}
SET_BIT(GPIOA->BSRRH, 
0
b
10000
); //Sets pin 
4
low
transmitData[
0
]=
0
x
80
; //UPDATE LINE
transmitData[
1
]=
0
xD
2
; 
transmitData[
2
]=
0
xF
0
;
transmitData[
3
]=
0
xF
0
;
transmitData[
4
]=
0
xF
0
;
transmitData[
5
]=
0
xF
0
;
transmitData[
6
]=
0
xF
0
;
transmitData[
7
]=
0
xF
0
;
transmitData[
8
]=
0
xF
0
;
transmitData[
9
]=
0
xF
0
;
transmitData[
10
]=
0
xF
0
;
transmitData[
11
]=
0
xF
0
;
transmitData[
12
]=
0
xF
0
;
transmitData[
13
]=
0
xF
0
;
transmitData[
14
]=
0
xF
0
;
transmitData[
15
]=
0
xF
0
;
transmitData[
16
]=
0
xF
0
;
transmitData[
17
]=
0
xF
0
;
transmitData[
18
]=
0
x
00
;
transmitData[
19
]=
0
x
00
;
//Send update message over SPI
1
forever
SET_BIT(GPIOA->BSRRL, 
0
b
10000
); //Sets pin 
4
high
for(j = 
0
; j < 
20
; j++) {
//TM_SPI_Send(SPI
3
, transmitData[j]);
SPI
3
->DR = transmitData[j]; // Write data to the data register
while( !(READ_BIT(SPI
3
->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
while( READ_BIT(SPI
3
->SR, SPI_SR_BSY) );
}
//osDelay(
10
);
SET_BIT(GPIOA->BSRRH, 
0
b
10000
); //Sets pin 
4
low
transmitData[
0
]=
0
x
80
; //UPDATE LINE
transmitData[
1
]=
0
x
52
; 
transmitData[
2
]=
0
x
0
F;
transmitData[
3
]=
0
x
0
F;
transmitData[
4
]=
0
x
0
F;
transmitData[
5
]=
0
x
0
F;
transmitData[
6
]=
0
x
0
F;
transmitData[
7
]=
0
x
0
F;
transmitData[
8
]=
0
x
0
F;
transmitData[
9
]=
0
x
0
F;
transmitData[
10
]=
0
x
0
F;
transmitData[
11
]=
0
x
0
F;
transmitData[
12
]=
0
x
0
F;
transmitData[
13
]=
0
x
0
F;
transmitData[
14
]=
0
x
0
F;
transmitData[
15
]=
0
x
0
F;
transmitData[
16
]=
0
x
0
F;
transmitData[
17
]=
0
x
0
F;
transmitData[
18
]=
0
x
00
;
transmitData[
19
]=
0
x
00
;
//Send update message over SPI
1
forever
SET_BIT(GPIOA->BSRRL, 
0
b
10000
); //Sets pin 
4
high
for(j = 
0
; j < 
20
; j++) {
//TM_SPI_Send(SPI
3
, transmitData[j]);
SPI
3
->DR = transmitData[j]; // Write data to the data register
while( !(READ_BIT(SPI
3
->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
while( READ_BIT(SPI
3
->SR, SPI_SR_BSY) );
}
SET_BIT(GPIOA->BSRRH, 
0
b
10000
); //Sets pin 
4
low
transmitData[
0
]= MODE_DISPLAY;
transmitData[
1
]=
0
x
00
;
SET_BIT(GPIOA->BSRRL, 
0
b
10000
); //Sets pin 
4
high
for(j = 
0
; j < 
2
; j++) {
//TM_SPI_Send(SPI
3
, transmitData[j]);
SPI
3
->DR = transmitData[j]; // Write data to the data register
while( !(READ_BIT(SPI
3
->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
while( READ_BIT(SPI
3
->SR, SPI_SR_BSY) );
}
SET_BIT(GPIOA->BSRRH, 
0
b
10000
); //Sets pin 
4
low
}
}

#spi-registers-dr-helpmeclive
6 REPLIES 6
Posted on August 21, 2014 at 18:48

Don't expect the debugger to show you the content of a write-only data register you have written. It's not a memory cell, and it's not visible to you. Observe the data at the pin.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cns1307
Associate II
Posted on August 21, 2014 at 19:01

I've been looking at the output pins with an oscilloscope, and I'm not seeing data or clock out. Thank you for the tip on the data register, I didn't realize that.

Posted on August 21, 2014 at 19:26

I'm not up for wading through register level code, trying using the Standard Library to configure the pins, mux, peripherals.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cns1307
Associate II
Posted on August 21, 2014 at 19:35

I looked into that, but I'm currently working in CrossStudio and the stm32f3xx_spi and gpio files didn't come with any of the packages.

Posted on August 21, 2014 at 21:03

Red Download Button, bottom of the page

http://www.st.com/web/en/catalog/tools/PF259429

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III
Posted on August 22, 2014 at 08:51

''I'm currently working in CrossStudio''

That's Rowley: 

http://www.rowley.co.uk/arm/

- yes?

''the stm32f3xx_spi and gpio files didn't come with any of the packages''

So download them from ST, then!