From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20120 invoked by alias); 1 Jul 2011 16:25:45 -0000 Received: (qmail 20105 invoked by uid 22791); 1 Jul 2011 16:25:41 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from tirion.supremecenter202.com (HELO tirion.supremecenter202.com) (209.25.195.243) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jul 2011 16:25:25 +0000 Received: from [89.185.209.155] (port=59810 helo=[192.168.1.105]) by tirion.supremecenter202.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1QcgWv-0004iE-UM; Fri, 01 Jul 2011 16:25:23 +0000 Message-ID: <4E0DF4E5.1040009@siva.com.mk> Date: Fri, 01 Jul 2011 16:25:00 -0000 From: Ilija Stanislevik User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: ecos-discuss@ecos.sourceware.org CC: jayant biswas References: <4DE6749E.8050001@siva.com.mk> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: Re: [ECOS] SPI send data X-SW-Source: 2011-07/txt/msg00004.txt.bz2 On 06/30/2011 04:20 PM, jayant biswas wrote: > It's been a while since the last message. But I am still stuck on this > problem, which means that I am unable to control the programmable > potentiometer AD8400. So I have tried to check the pins with a logic > analyzer and it appears that I do not see any SPI clock. That is to > say that the pin PA5 is always low. As is the pin PA7. And PA8 is > always high. This pins correspond to the descriptions in the STM3210E > eval board http://www.st.com/stonline/products/literature/um/14220.pdf > . Am I missing some initialization step that should start off the > clock? > > I have attached my code with this message. Please let me know if you > need more information. > > Thank you, > Jayant > > On Wed, Jun 1, 2011 at 19:19, Ilija Stanislevik wrote: >> On 06/01/2011 11:02 AM, jayant biswas wrote: >>> Hi Ilija, >>> >>> Thank you for your response to the previous question, I am using SPI1 >>> and have changed the config accordingly and have noticed with a >>> voltmeter that the pin PA8 does stay high and goes low when the SPI is >>> active. I have another question now about sending data. If you take a >>> look at the timing diagrams on page 10 of the datasheet >>> (http://www.analog.com/static/imported-files/data_sheets/AD8400_8402_8403.pdf) >>> for the programmable potentiometer that I am using and then my code >>> below, could you maybe hint at what I am doing wrong? >>> >>> Regards, >>> Jayant >>> >>> So this code based on the loopback test that comes with the spi package in ecos. >>> >>> #include >>> #include // Test macros >>> #include // Assertion macros >>> #include // Diagnostic output >>> >>> #include // CYGNUM_HAL_STACK_SIZE_TYPICAL >>> #include >>> >>> #include // Common SPI API >>> #include // STM32 data structures >>> >>> #include >>> >>> //--------------------------------------------------------------------------- >>> // Thread data structures. >>> >>> cyg_uint8 stack [CYGNUM_HAL_STACK_SIZE_TYPICAL]; >>> cyg_thread thread_data; >>> cyg_handle_t thread_handle; >>> >>> externC cyg_spi_cortexm_stm32_bus_t cyg_spi_stm32_bus2; >>> >>> //--------------------------------------------------------------------------- >>> // SPI loopback device driver data structures. >>> >>> cyg_spi_cortexm_stm32_device_t loopback_device = { >>> .spi_device.spi_bus = &cyg_spi_stm32_bus1.spi_bus, >>> .dev_num = 0 , // Only 1 device. >>> .cl_pol = 1, >>> .cl_pha = 1, >>> .cl_brate = 8000000, // Nominal 8Mhz. >>> .cs_up_udly = 1, >>> .cs_dw_udly = 1, >>> .tr_bt_udly = 1, >>> .bus_16bit = true, // *** MODIFIED this because my data is 10 bits >>> }; >>> >>> //--------------------------------------------------------------------------- >>> >>> //const char tx_data[] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}; // To set >>> maximum resistance at address 00 >>> const char tx_data[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // To set >>> minimim resistance at address 00 >>> const char tx_data1[] = "Testing extended API..."; >>> const char tx_data2[] = "Testing extended API for a second transaction."; >>> >>> char rx_data [sizeof(tx_data)]; >>> char rx_data1 [sizeof(tx_data1)]; >>> char rx_data2 [sizeof(tx_data2)]; >>> >>> //--------------------------------------------------------------------------- >>> // Run single loopback transaction using simple transfer API call. >>> >>> void run_test_1 (cyg_bool polled) >>> { >>> diag_printf ("Test 1 : Simple transfer test (polled = %d).\n", >>> polled ? 1 : 0); >>> cyg_spi_transfer (&loopback_device.spi_device, polled, sizeof (tx_data), >>> (const cyg_uint8*) &tx_data[0], (cyg_uint8*) &rx_data[0]); >>> >>> diag_printf (" Tx data : %s\n", tx_data); >>> diag_printf (" Rx data : %s\n", rx_data); >>> CYG_ASSERT (memcmp (tx_data, rx_data, sizeof (tx_data)) == 0, >>> "Simple transfer loopback failed - mismatched data.\n"); >>> } >>> >>> >>> //--------------------------------------------------------------------------- >>> // Run all PL022 SPI interface loopback tests. >>> >>> void run_tests (void) >>> { >>> diag_printf ("Running STM32 SPI driver loopback tests.\n"); >>> run_test_1 (true); >>> CYG_TEST_PASS_FINISH ("Loopback tests ran OK"); >>> } >>> >>> //--------------------------------------------------------------------------- >>> // User startup - tests are run in their own thread. >>> >>> void cyg_user_start(void) >>> { >>> CYG_TEST_INIT(); >>> cyg_thread_create( >>> 10, // Arbitrary priority >>> (cyg_thread_entry_t*) run_tests, // Thread entry point >>> 0, // >>> "test_thread", // Thread name >>> &stack[0], // Stack >>> CYGNUM_HAL_STACK_SIZE_TYPICAL, // Stack size >>> &thread_handle, // Thread handle >>> &thread_data // Thread data structure >>> ); >>> cyg_thread_resume(thread_handle); >>> cyg_scheduler_start(); >>> } >>> >>> //============================================================================= >>> >> First you should change >> >> .cl_pol = 1, >> .cl_pha = 1, >> >> into >> >> .cl_pol = 0, >> .cl_pha = 0, >> >> >> in order to make STM32 SPI's timing compatible with potentiometer. >> >> Note that with cyg_spi_transfer() you can send/receive bytes or 16bit >> words, while your potentiometer expects 10bit words. You should take >> care to pack your 10bit word in 16bits (two consecutive bytes) aligned >> towards LS bit. That way STM32's SPI will clock out 6 unused bits at the >> beginning so at the end of transaction your 10 bits will settle in right >> place in potentiometer's shift register. >> >> const char tx_data[] = {0,0xff}; // To set maximum resistance at address 00 >> const char tx_data[] = {0,0}; // To set minimum resistance at address 00 >> >> >> In your attempt you are packing a bit in each byte (char) which is wrong. >> >> Also change >> >> .bus_16bit = true, >> >> into >> >> .bus_16bit = false, >> >> because you are sending/receiving in 8bit portions. >> >> Regards, >> -- >> >> Ilija Stanislevik >> SIvA doo >> ul. Mladinska 43 lok. 6 >> p.f. 53 >> MK-2400 Strumica >> Macedonia >> >> www.siva.mk >> >> Hi, Did you retry the test with MISO, MOSI lines shorted (loop back)? Regards, -- Ilija Stanislevik SIvA doo ul. Mladinska 43 lok. 6 p.f. 53 MK-2400 Strumica Macedonia www.siva.mk -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss