4 years, 12 months ago.

same SPI program work well in online compiler, while failed in the keil

SPI program is normal on mbed online compiler. The generated bin file is burned on STM32 discovery board and the oscilloscope shows normal. It is exported to keil and compiled again. SPI does not work. After a day of searching, I couldn't find the problem. PS: KEIL does not display errors。 /media/uploads/EvanWu_1/spi_work_well.gif

include the mbed library with this snippet

#include "mbed.h"
#include <DigitalOut.h> 
//DigitalOut myled(LED1);
DigitalOut myled(PD_13);

SPI ser_port(PB_5,PB_4,PB_3);
DigitalOut cs(PB_9);//私有对象成员cs
DigitalOut ldac(PE_0);//私有对象成员ldac
DigitalOut reset(PE_8);//私有对象成员reset

//SPI ser_port(PB_5,PB_4,PB_3);
//char switch_word;
int switch_wordx;
int switch_wordy;
//Serial usart1(PB_6,PB_7,9600);//RS232通讯端口为PD8,PD9
//Serial usart3(PD_8,PD_9,9600);//RS232通讯端口为PD8,PD9
//Serial usart3(PB_10,PB_11,9600);//RS232通讯端口为PD8,PD9 
//Serial usart3(PC_10,PC_11,9600);//RS232通讯端口为PD8,PD9
//Serial usart1(PA_9,PA_10,9600);//RS232通讯端口为PD8,PD9
//Serial usart1(PA_9,PB_7,9600);//RS232通讯端口为PD8,PD9
//Serial usart2(PA_2,PA_3,9600);//RS232通讯端口为PD8,PD9
/////Serial usart6(PC_6,PC_7,9600);//RS232通讯端口为PD8,PD9
int main() {
/*    while(1) {
        myled = 1;
        wait(0.5);
        myled = 0;
        wait(0.5);    
        //usart1.printf("Hello World\n");
        //usart2.printf("Hello World\n");          
        usart6.printf("Hello World\n");   
    }
*/
    ser_port.format(16);
    ser_port.frequency(1000000);
    while(1)
        {
            ldac =1;    
            cs =1;
            
            cs =0;//拉低cs电平,SCLK正常工作、使能移位寄存器(时钟输出=cs+sclk)
            ldac =1;    
                
            switch_wordx=0xA0A0;
            switch_wordy=0xA1A1;
            ser_port.write(switch_wordx);    
            wait_us(1);
            ser_port.write(switch_wordy);
            wait_us(1);
            cs =1;
            
            ldac=0;
            wait_us(1);
            ldac=1;
                        
            wait_us(20);
        }            
}

Hi,

exporter project might not have the same properties set in the project itself. I would check develop profile (flags) and compare to the one in uvision project. First guess, optimization settings are different and once equal, might show this issue.

posted by Martin Kojtal 29 Apr 2019
Be the first to answer this question.