<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: (CAN bus) hardware not setting/ resetting bits</title>
		<link>http://forums.leaflabs.com/topic.php?id=2121</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:07:51 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=2121" rel="self" type="application/rss+xml" />

		<item>
			<title>ee52bs on "(CAN bus) hardware not setting/ resetting bits"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2121#post-11785</link>
			<pubDate>Tue, 17 Jul 2012 04:55:30 +0000</pubDate>
			<dc:creator>ee52bs</dc:creator>
			<guid isPermaLink="false">11785@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi, thanks for the reply. My initialisation code is as follows;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
(CAN_CTRL-&#38;gt;MCR) &#38;amp;= ~(1&#38;lt;&#38;lt;MCR_SLEEP); //clear sleep bit&#60;br /&#62;
(CAN_CTRL-&#38;gt;MCR) &#124;= 1 &#38;lt;&#38;lt; MCR_INRQ; //set init request bit&#60;/p&#62;
&#60;p&#62;while(can_get_mode() != INIT){} //wait to get into init mode&#60;/p&#62;
&#60;p&#62;//set baud rate&#60;br /&#62;
CAN_CTRL-&#38;gt;BTR &#124;= 0x324000E; //SJW = 3, BS2 = 2, BS1 = 4, BRP = 14 approx 250kHz&#60;/p&#62;
&#60;p&#62;//set mode&#60;br /&#62;
if(mode == LBK)&#60;br /&#62;
(CAN_CTRL-&#38;gt;BTR) &#124;= 1&#38;lt;&#38;lt;BTR_LBKM; //turn on loopback mode&#60;/p&#62;
&#60;p&#62;//set up filters&#60;br /&#62;
can_f_setup();&#60;/p&#62;
&#60;p&#62;//set up MCR&#60;br /&#62;
(CAN_CTRL-&#38;gt;MCR) &#124;= 1 &#38;lt;&#38;lt; MCR_NART; //set no automatic retransmission&#60;br /&#62;
(CAN_CTRL-&#38;gt;MCR) &#38;amp;= ~(1&#38;lt;&#38;lt;MCR_INRQ); //clear INRQ bit&#60;br /&#62;
while((CAN_CTRL-&#38;gt;MSR) &#38;amp; (1&#38;lt;&#38;lt;MSR_INAK)){} //wait to get back into normal mode&#60;/p&#62;
&#60;p&#62;return can_get_mode();&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;I checked that it does go into initialisation mode and then goes back into normal mode once everythin has been set up, however I still have the same problem with the flags not being set or reset.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bateman on "(CAN bus) hardware not setting/ resetting bits"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2121#post-11762</link>
			<pubDate>Mon, 16 Jul 2012 04:45:59 +0000</pubDate>
			<dc:creator>bateman</dc:creator>
			<guid isPermaLink="false">11762@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Now that I've refreshed my memory a bit, it doesn't look like you're initialising the bxCAN controller. To do this you need to:&#60;/p&#62;
&#60;p&#62;* Set the INRQ bit in the bxCAN's MCR register.&#60;br /&#62;
* Poll the MSR register and wait for the INAK bit to be set.&#60;/p&#62;
&#60;p&#62;After that the controller is in initialisation mode. Now is the time to configure your baud rate and filters. I also like to enable automatic bus-off management here by setting the ABOM bit in the MCR register.&#60;/p&#62;
&#60;p&#62;Once you've got the controller configured to your liking you need to put the controller into normal mode so that it syncs to the CAN bus:&#60;/p&#62;
&#60;p&#62;* Clear the INRQ bit in the bxCAN MCR register.&#60;br /&#62;
* Poll the MSR register and wait for the INAK bit to clear.&#60;/p&#62;
&#60;p&#62;Once that's done you should be on the bus and be able to transmit.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bateman on "(CAN bus) hardware not setting/ resetting bits"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2121#post-11736</link>
			<pubDate>Sat, 14 Jul 2012 09:04:33 +0000</pubDate>
			<dc:creator>bateman</dc:creator>
			<guid isPermaLink="false">11736@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ah, so you have. I beg your pardon: it was chucking-out time at work on Friday when I noticed your post, so I only had a very quick skim of your code before posting. I'll have another look when I get back on Monday.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ee52bs on "(CAN bus) hardware not setting/ resetting bits"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2121#post-11723</link>
			<pubDate>Fri, 13 Jul 2012 11:01:09 +0000</pubDate>
			<dc:creator>ee52bs</dc:creator>
			<guid isPermaLink="false">11723@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yup &#60;code&#62;(RCC_BASE-&#38;gt;APB1ENR) = 0x2000007; //enable CAN clock, disable USB clock&#60;/code&#62; sets USBEN to 0 and CANEN to 1
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bateman on "(CAN bus) hardware not setting/ resetting bits"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2121#post-11722</link>
			<pubDate>Fri, 13 Jul 2012 10:41:12 +0000</pubDate>
			<dc:creator>bateman</dc:creator>
			<guid isPermaLink="false">11722@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Have you disabled the USB interface's APB1 clock feed and enabled the bxCAN's from the RCC? (They have one block of SRAM between them, so you can't have both active at the same time.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ee52bs on "(CAN bus) hardware not setting/ resetting bits"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2121#post-11703</link>
			<pubDate>Thu, 12 Jul 2012 09:00:31 +0000</pubDate>
			<dc:creator>ee52bs</dc:creator>
			<guid isPermaLink="false">11703@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I am trying to get the CAN bus working in loopback mode on an Olimexino STM32. I have tried the libraries from STM, and x893's code from this forum, and the Keil example code, and I am still having the same problem: The bus initialises OK, returns to normal mode OK, I set up the TX mailbox OK (I checked the register values), but when I set the TXRQ bit nothing happens and the bus remains idle. I also checked aborting the transmission by setting the ABRQ bit but the mailbox isn't cleared. It appears that the hardware is not responding to the software setting bits, which I figured must be due to a problem with the low level interface setup, but I've checked the register addresses in the STM32 manual and the pins in the Olimexino manual and I can't see anything wrong. Below is my initialisation code:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
nvic_globalirq_disable();// disable all interrupts&#60;/p&#62;
&#60;p&#62;rcc_clk_enable(RCC_GPIOB);&#60;br /&#62;
rcc_clk_enable(RCC_AFIO);// enable clocks for AFIO&#60;br /&#62;
(RCC_BASE-&#38;gt;APB1ENR) = 0x2000007; //enable CAN clock, disable USB clock&#60;br /&#62;
(RCC_BASE-&#38;gt;CFGR) &#124;= 1&#38;lt;&#38;lt;CFGR_USBPRE; //turn off USB prescaler&#60;/p&#62;
&#60;p&#62;(RCC_BASE-&#38;gt;APB2RSTR) = 0x9; //assert GPIO reset&#60;br /&#62;
(RCC_BASE-&#38;gt;APB2RSTR) = 0x0; //release GPIO reset&#60;/p&#62;
&#60;p&#62;(RCC_BASE-&#38;gt;APB1RSTR) = 0x2000000; //assert CAN reset&#60;br /&#62;
(RCC_BASE-&#38;gt;APB1RSTR) = 0x0; //release CAN reset&#60;/p&#62;
&#60;p&#62;afio_remap(AFIO_REMAP_CAN_1);&#60;br /&#62;
gpio_set_mode(GPIOB, 8, GPIO_INPUT_FLOATING);&#60;br /&#62;
gpio_set_mode(GPIOB, 9, GPIO_AF_OUTPUT_PP);&#60;/p&#62;
&#60;p&#62;//enable interrupts&#60;br /&#62;
nvic_irq_enable(NVIC_USB_LP_CAN_RX0);	// enable NVIC interrupts&#60;br /&#62;
nvic_irq_enable(NVIC_USB_HP_CAN_TX);&#60;br /&#62;
nvic_globalirq_enable();//enable all interrupts&#60;/p&#62;
&#60;p&#62;(CAN_CTRL-&#38;gt;IER) &#124;= 1&#38;lt;&#38;lt;IER_FMPIE0; //set FIFO0 empty interrupt bit&#60;br /&#62;
(CAN_CTRL-&#38;gt;IER) &#124;= 1&#38;lt;&#38;lt;IER_FMPIE1; //set FIFO1 empty interrupt bit&#60;br /&#62;
(CAN_CTRL-&#38;gt;IER) &#124;= 1&#38;lt;&#38;lt;IER_TMEIE; //set TX MB empty interrupt bit&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;The only things I can think of is that there is some interrupt which should occur which hasn't been enabled, or else there is still some interference between the USB and CAN bus. Any ideas?&#60;/p&#62;
&#60;p&#62;Cheers, &#60;/p&#62;
&#60;p&#62;Ben
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
