Академический Документы
Профессиональный Документы
Культура Документы
Search
Search
Advanced search
Register
Login
9 posts Page 1 of 1
Search
I've been playing with the STM32 lately and I have to say I'm quite impressed. However I found the first tiny little issue
that is frustrating. The SPI peripheral. I'm using the Nokia 6100/6610 display and it has this odd 9- bit data frame.
Unfortunately the STM32 will only allow 8 or 16 bit frames. So it looks like I will have to bit- bang the SPI. No big deal I
know but I'm one for throwing a byte at a register and letting my code get on with things. Having to sit around and babysit
the SPI is frustrating.
sgome s
Po s ts : 9
J o ine d : Fri J an 0 8 , 20 10 11:19 p m
Lo c atio n: Camp b e ll, CA USA
Anyone have a clever idea how to use the 16- bit mode to produce a 9- bit frame? Hmmm I just had a thought....maybe
use a USART in synchronous mode somehow....
Shannon
Las t e d ite d b y s g o me s o n We d Fe b 10 , 20 10 11:57 p m, e d ite d 1 time in to tal.
T
The USARTS on the STM32 can be run in synchronous mode where they behave exactly like a SPI peripheral and they
support 8 or 9 data bits.
pe t e h
Site Ad min
Po s ts : 49 4
J o ine d : We d J an 25, 20 0 6 4:11 p m
Lo c atio n: Lic hfie ld , Staffo rd s hire
PDFmyURL.com
yep exactly right. What a relief it was to read the reference manual and find that they have all the bits for doing 8 or 9 bit
SPI via the USARTs. Man this is a fantastic chip!
sgome s
Po s ts : 9
J o ine d : Fri J an 0 8 , 20 10 11:19 p m
Lo c atio n: Camp b e ll, CA USA
sgome s
Po s ts : 9
PDFmyURL.com
Just discovered another caveat. The SPI bus is a MSB first bus and the USART is a LSB first bus. So to use the USART
in SPI mode you'll have to reverse the order of the data bits before stuffing it into the transmit register.
I asked ST about this issue of MSB first vs. LSB first. Apparently it is true that if using the USART for SPI communication
you DO have to reverse the order of the bits. However there is an easy way to do it. I've copied his response below:
sgome s
Po s ts : 9
J o ine d : Fri J an 0 8 , 20 10 11:19 p m
Lo c atio n: Camp b e ll, CA USA
Dear User,
Please find here belo w latest info rmatio n co ncerning the request R10 0 6 0 10 0
Yo u are co rrect. There is no reverse bit in the USART registers.
There is, ho wever, a 1 clo ck cycle Thumb2 instructio n that will do it fo r yo u. RBIT. There's also a macro in the STM32
Standard library That allo ws yo u to call the assy lang. instructio n fro m C.
A co py o f it belo w:
CO DE: SELECT ALL
/**
* @brief Reverse bit order of value
*
* @param uint32_t value to reverse
* @return uint32_t reversed value
*
* Reverse bit order of value
*/
uint32_t __RBIT(uint32_t value)
{
PDFmyURL.com
pe t e h
Site Ad min
Po s ts : 49 4
J o ine d : We d J an 25, 20 0 6 4:11 p m
Lo c atio n: Lic hfie ld , Staffo rd s hire
You can have it cheap, good and soon - pick any two.
T
Im trying to interface Nokia LCD 6610 to STM32L through sync USART. Though there is clock and data on MOSI and
SCK pins LCD isnt displaying anything. Below is the code i've used for transfer of data through USART
USART_DeInit(USART2);
USART_InitStructure.USART_BaudRate =0x02255100;//0x0001C200; // baud rate=115200
USART_InitStructure.USART_WordLength =USART_WordLength_9b;
USART_InitStructure.USART_StopBits =USART_StopBits_1;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_Mode=USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_Init(USART2, &USART_InitStructure);
re va
Po s ts : 3
J o ine d : Sat Ap r 28 , 20 12 6 :47 p m
USART_ClkInitStructure.USART_Clock= USART_Clock_Enable;
USART_ClkInitStructure.USART_CPOL=USART_CPOL_Low;
USART_ClkInitStructure.USART_CPHA=USART_CPHA_1Edge;
USART_ClkInitStructure.USART_LastBit=USART_LastBit_Enable;
USART_ClockInit(USART2, &USART_ClkInitStructure);
USART_Cmd(USART2,ENABLE);
T
re va
Po s ts : 3
J o ine d : Sat Ap r 28 , 20 12 6 :47 p m
PDFmyURL.com
}
void WriteSpiCommand(unsigned int data)
{
hey!! i changed the settings to USART1 .. a better USART in terms of speed ... and..... behold its workin! ... jus done wid
re va
Po s ts : 3
J o ine d : Sat Ap r 28 , 20 12 6 :47 p m
PDFmyURL.com
my demo
) ...
Thanks guys \m/...........
really thank sgomes ... the data reversal was quite helpful
CHANGED USART settings
USART_DeInit(USART1);
USART_InitStructure.USART_BaudRate =0x00011114;//0x0001C200; // baud rate=115200
USART_InitStructure.USART_WordLength =USART_WordLength_9b;
USART_InitStructure.USART_StopBits =USART_StopBits_1;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_Mode=USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_Init(USART1, &USART_InitStructure);
USART_ClkInitStructure.USART_Clock= USART_Clock_Enable;
USART_ClkInitStructure.USART_CPOL=USART_CPOL_Low;
USART_ClkInitStructure.USART_CPHA=USART_CPHA_1Edge;
USART_ClkInitStructure.USART_LastBit=USART_LastBit_Enable;
USART_ClockInit(USART1, &USART_ClkInitStructure);
USART_Cmd(USART1,ENABLE);
T
All posts
Sort by
Post time
Ascending
Go
Post a reply
9 posts Page 1 of 1
Return to Electronics
Jump to:
Electronics
Go
WHO IS O N LIN E
Users browsing this forum: No registered users and 1 guest
The team Delete all board cookies All times are UTC
Board index
Po we re d b y p hp BB Fo rum So ftware p hp BB G ro up
PDFmyURL.com